Post Reply 
RPL beginner
11-07-2021, 01:38 PM
Post: #13
RE: RPL beginner
OK, it's now more obvious where you are headed with this animation. Very well done!

Using TOGGLELINE#3 worked with the previous versions of your code, given that there was only one line being drawn at the time. In the previous scenario, TOGGLELINE#3 would just clear the line that was just drawn. I would suggest that TOGGLELINE#3 is no longer appropriate with this most recent update, though, as it leaves stray pixels active in locations where previously-drawn lines overlap with previously-cleared lines.

The original use of LINEON/LINEOFF now appears to be the better approach. That being the case, you could keep the drawing on the alpha display instead of switching to the graph display. This would negate the need to save the user PICT area and switch to that display, as well as correctly turning off all of the appropriate pixels for each previous line. Using LINEON/LINEOFF requires the occasional reordering of input pairs, though, so that requirement needs to be accommodated in the code. This seems like a good time to introduce the use of a subroutine.

Calling subroutines in the context of an RPL library is very straightforward, but that's out-of-scope for this situation. Here, I would suggest doing it in a very similar manner to what you might do with a UserRPL implementation: save the subroutine as a local variable, then recall/EVAL it as needed for execution.

I've taken your most recent code and modified it as follows:
  • formatted some of the commands more "horizontally" to provide visual cues about the grouping
  • switched back to using the text/alpha display for drawing
  • created a line-drawing subroutine for drawing and clearing lines

I believe this provides a more faithful rendering of the animation that you originally intended.

Code:
::
   ( no arguments expected )
   CK0NOLASTWD

   ( setup/clear display )
   ClrDA1IsStat
   RECLAIMDISP
   TURNMENUOFF

   ( place line drawing subroutine on the stack )
   ' ::
      (
         DrwLn: Given line endpoints and a boolean, draws or clears the line
                designated by the endpoints in the text/alpha display.

         Input
            SL5: X1
            SL4: Y1
            SL3: X2
            SL2: Y2
            SL1: TRUE [draw] or FALSE [clear]

         Output
            Draws or clears a line in alpha/text display
      )
      5UNROLL                    ( move boolean to top of args )
      4PICK 3PICK #> IT 2SWAP    ( order endpoints as needed )
      5ROLL ITE LINEON LINEOFF   ( draw or clear line )
   ;

   ( allocate locals 131x64)
   90 30       ( x1=90 y1=30 )
   60 0        ( x2=50 y2=10 )
   5 -5        ( dx1 dy1 )
   -5 5        ( dx2 dy2 )

   10 10       ( x3=10 y3=10 )
   120 40      ( x4=120 y4=50 )
   5 5         ( dx3 dy3 )
   5 5         ( dx4 dy4 )
   {
      LAM DrwLn

      LAM X1   LAM Y1
      LAM X2   LAM Y2
      LAM DX1  LAM DY1
      LAM DX2  LAM DY2
      LAM X3   LAM Y3
      LAM X4   LAM Y4
      LAM DX3  LAM DY3
      LAM DX4  LAM DY4
   } BIND

   ( clear key buffer )
   FLUSHKEYS ATTNFLGCLR

   ( loop until a key is pressed )
   BEGIN
      KEYINBUFFER? ATTN? OR NOT
   WHILE
      ( draw current line )
      LAM X1 LAM Y1
      LAM X2 LAM Y2
      TRUE
      LAM DrwLn EVAL

      ( brief pause for emulator )
      % 0.02 dowait

      ( clear previous line )
      LAM X3 LAM Y3
      LAM X4 LAM Y4
      FALSE
      LAM DrwLn EVAL

      ( change Y3 value )
      LAM Y3 LAM DY3 #+
      ' LAM Y3 STO

      ( change X3 value )
      LAM X3 LAM DX3 #+
      ' LAM X3 STO

      ( change Y4 value )
      LAM Y4 LAM DY4 #+
      ' LAM Y4 STO

      ( change X4 value )
      LAM X4 LAM DX4 #+
      ' LAM X4 STO

      ( change Y1 value )
      LAM Y1 LAM DY1 #+
      ' LAM Y1 STO

      ( change X1 value )
      LAM X1 LAM DX1 #+
      ' LAM X1 STO

      ( change Y2 value )
      LAM Y2 LAM DY2 #+
      ' LAM Y2 STO

      ( change X2 value )
      LAM X2 LAM DX2 #+
      ' LAM X2 STO

      ( change DX4 value if appropriate )
      LAM X4 130 #= IT ::
          -5
        ' LAM DX4 STO
      ;
      LAM X4 #0= IT ::
         5
         ' LAM DX4 STO
      ;

      ( change DY4 value if appropriate )
      LAM Y4 SIXTY #= IT ::
         -5
         ' LAM DY4 STO
      ;
      LAM Y4 #0= IT ::
         5
         ' LAM DY4 STO
      ;

      ( change DX3 value if appropriate )
      LAM X3 130 #= IT ::
          -5
        ' LAM DX3 STO
      ;
      LAM X3 #0= IT ::
         5
         ' LAM DX3 STO
      ;

      ( change DY1 value if appropriate )
      LAM Y3 SIXTY #= IT ::
         -5
         ' LAM DY3 STO
      ;
      LAM Y3 #0= IT ::
         5
         ' LAM DY3 STO
      ;

      ( change DX1 value if appropriate )
      LAM X1 130 #= IT ::
          -5
        ' LAM DX1 STO
      ;
      LAM X1 #0= IT ::
         5
         ' LAM DX1 STO
      ;

      ( change DY1 value if appropriate )
      LAM Y1 SIXTY #= IT ::
         -5
         ' LAM DY1 STO
      ;
      LAM Y1 #0= IT ::
         5
         ' LAM DY1 STO
      ;

      ( change DY2 value if appropriate )
      LAM Y2 SIXTY #= IT ::
         -5
         ' LAM DY2 STO
      ;
      LAM Y2 #0= IT ::
         5
         ' LAM DY2 STO
      ;

      ( change DX2 value if appropriate )
      LAM X2 130 #= IT ::
         -5
         ' LAM DX2 STO
      ;
      LAM X2 #0= IT ::
         5
         ' LAM DX2 STO
      ;

   REPEAT

   ( clear pressed key )
   FLUSHKEYS ATTNFLGCLR

   ( abandon locals )
   ABND

   ( reset display )
   ClrDAsOK
;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL beginner - dwesti - 10-30-2021, 07:23 PM
RE: RPL beginner - David Hayden - 11-01-2021, 02:11 PM
RE: RPL beginner - dwesti - 11-01-2021, 04:40 PM
RE: RPL beginner - DavidM - 11-02-2021, 10:51 AM
RE: RPL beginner - dwesti - 11-02-2021, 02:18 PM
RE: RPL beginner - dwesti - 11-02-2021, 05:20 PM
RE: RPL beginner - DavidM - 11-04-2021, 01:07 AM
RE: RPL beginner - dwesti - 11-04-2021, 09:21 AM
RE: RPL beginner - DavidM - 11-04-2021, 09:49 AM
RE: RPL beginner - dwesti - 11-04-2021, 04:04 PM
RE: RPL beginner - DavidM - 11-05-2021, 10:12 AM
RE: RPL beginner - dwesti - 11-06-2021, 06:41 PM
RE: RPL beginner - DavidM - 11-07-2021 01:38 PM
RE: RPL beginner - dwesti - 11-08-2021, 05:40 PM
RE: RPL beginner - DavidM - 11-11-2021, 02:33 AM
RE: RPL beginner - dlidstrom - 11-13-2021, 08:04 PM
RE: RPL beginner - BINUBALL - 11-14-2021, 02:06 AM
RE: RPL beginner - DavidM - 11-14-2021, 12:49 PM



User(s) browsing this thread: 1 Guest(s)