[comp.sys.handhelds] Graphing Program

adams@hpfelg.HP.COM (John Adams) (12/30/89)

	 Currently the 28s only supports scatter plots or drawing
      equations.  This program reads the scatter data in the 'sDAT'
      (SigmaDAT) variable and performs a connect the dots output. The
      user can scale and translate the grahical output exactly like any
      normal graphical operation.

         The  program  "Graphit"  is used to parse the  independent  and
      dependent  variables and calculates the x,y step sizes in order to
      optimize the output  performance.  Since the PPAR values are used,
      all  PMIN,   PMAX,  RES  *W,  *H,  etc.  values   are  taken  into
      consideration.

         The routine doing all the work is Connect.  This routine  takes
      6 items from the stack; two  coordinates, x, and y step increment.
      The routine  then draws a line from the second  coord to the first
      at a  resolution  given by the RES value.  The  routine  "Connect"
      routine is low level enough to build upon (bar graph?).

      NOTE:  Could someone post this to the list server.

John Adams

-----------------------------------------------------------------------
      

      Graphit [A005]
	requires a variable 'sDAT'
	takes/returns nothing from/to stack.

      { VARS 'PPAR' POS            ; check is PPAR exists,
        IF 0 ==                    ; if not then scale matrix
        THEN SCLs                  ; NOTE the 's' is a Sigma
        END 'PPAR(2)' EVAL         ; get PMAX, PMIN, and RES from PPAR
      C->R SWAP 'PPAR(1)'          ; and compute x and y step sizes
      EVAL C->R ROT ROT -          ; from (xmin-xmin)*res/137
      ROT ROT - 32 / SWAP          ; and (ymax-ymin)/32
      'PPAR(4)' EVAL * 137         ; 
      / sPAR LIST-> 3 DROPN        ; 
      sDAT SIZE LIST->             ; find number of elements to plot
      DROP2 2 CLLCD ->             ; set current coord pointer to 2nd
      ystep step xcol ycol         ; coordinate.
      max cnt                      ; 
	{ 'sDAT(1,xcol)'           ; push first coord onto stack
      EVAL 'sDAT(1,ycol)'          ;
      EVAL                         ;
	  DO 'sDAT(cnt,            ; push current coord onto stack
      xcol)' EVAL 'sDAT(           ;
      cnt,ycol)' EVAL 4            ; rearrange stack (xnew,ynew,xold,yold)
      ROLLD 4 ROLLD step           ; push x and y steps onto stack
      ystep Connect 1 cnt          ; and call Connect routine, increment
      + 'cnt' STO                  ; current pointer and make 'new' coord
	  UNTIL cnt max >          ; repeat for all points in matrix
	  END DROP2                ; leave stack as before.
        } DGTIZ                    ; enable interactive mode.
      }                            ;


      Connect [A0F7]
        requires from stack:
 	  xto
	  yto
	  xfrom
	  yfrom
	  xinc
	  yinc
        returns to the stack:
          xto
	  yto

      << -> x2 y2 x1 y1 step       ; Grab vectors from stack.
      ystep                        ;
	<< x2 y2 x1 y1 '           ; 
      SIGN(x2-x1)*step'            ; Calculate step w/direction
      EVAL 'step' STO '            ; store as step.
      SIGN(y2-y1)*ystep'           ; Do the same for the y direction
      EVAL 'ystep' STO             ;
	  IF step 0 ==             ; If line is vertical, set xstep 
	  THEN 0 ystep             ; to 0 and ystep to ystep.
	  ELSE step '(y2-          ; Otherwise set xstep to step and
      y1)/(x2-x1)*step'            ; ystep to the slope of the line.
      EVAL                         ;
	  END x1 y1 -> x2          ; Initialize the current coord.
      y2 x1 y1 xstep ystep         ;
      xx yy                        ;
	  <<                       ;
	    IF xstep 0 #           ; NOTE: # is the not equals symbol 
	    THEN x1 x2             ; For a non-vertical line, increment
	      FOR xx ystep         ; along the x axis and add the slope
      yy + 'yy' STO xx yy          ; to the y coord.
      R->C PIXEL xstep             ; Plot the coordinate and increment 
	       STEP                ; the x coord by xstep.
             ELSE y1 y2            ; ELSE if a vertical line we don't
	       FOR yy xx yy        ; need to bother with incrementing
      R->C PIXEL ystep             ; the x coord.
	       STEP                ;
             END x2 y2             ; Return the 'to' coordinate to the
           >>                      ; stack.
      >>                           ;