!*************************** AMUS Program Label ******************************
! Filename: GEARS.RUN                                       Date: 7/23/91
! Category: GRAP         Hash Code: 173-702-241-566      Version: 1.0
! Initials: LOW/AM       Name: David Krecklow
! Company: Compu-Center Co., Inc.                  Telephone #: 8053251004
! Related Files: GEARS.DOC
! Min. Op. Sys.: ANY                           Expertise Level: INT
! Special: AM-72 or other graphic terminal used under AMIGOS
! Description: AMIGOS version of the popular graph drawing game that uses
!              geared plastic parts to draw spiral graphs.
!
!*****************************************************************************
!
!
!
!GEARS - AMIGOS VERSION OF CLOID
!
!    GEARS                        NOTICE
!
!
!

       PROGRAM GEARS,1.0(000)

++INCLUDE AMGSYM.BSI                    ! get AMIGOS definitions

MAP1 GCB,X,32000                        ! Define graphics control block

! Point array for polyline calls
MAP1 POINT'ARRAY
       MAP2 POINT'COUNT,B,2
       MAP2 POINTS(20)
               MAP3 POINT'X,B,2
               MAP3 POINT'Y,B,2

MAP1 STATUS,F                           ! Status retruned from AMIGOS calls

MAP1 DESCX$(2)
       MAP2 DESC$,S,20

DESC$(1)="Epicycloid"
DESC$(2)="Hypocycloid"
XCNTR = 512                                     ! Center  - X
YCNTR = 384                                     !         - Y
XOFF=16383                                      ! Offset  - X
YOFF=12287                                      !         - Y
WINX=1024                                       ! Window  - X
WINY=1024                                       !         - Y

CLOID:
       ON ERROR GOTO END
                               ! Open the workstation
       XCALL AMGSBR,G'OPWK,GCB,"",STATUS
                               ! Set workstation window
       XCALL AMGSBR,G'SWKW,GCB,0+XOFF,0+YOFF,WINX+XOFF,WINY+YOFF,STATUS
                               ! Get the workstation status
       XCALL AMGSBR,G'QCHR,GCB,G'QCHR'MAP,STATUS
                               ! ? GH'MXW,GH'MXH,GH'MXV,GH'MYV,GH'CLP
       LOOKUP "GEARS.DAT",F'STAT
                               ! see if last run data exists and read it
       IF F'STAT<>0 THEN OPEN #1,"GEARS.DAT",INPUT : &
               INPUT #1,A,B,TP,STP,NOSTP,COLOR : &
               CLOSE #1
                               ! display last run data
       IF TP<>1 AND TP<>2 THEN TP=1 : DESC$(1)="NONE"

       ? "The last time GEARS ran "
       ? "      the fixed circle radius was ";A
       ? "    the rolling circle radius was ";B
       ? "            the type of graph was  ";DESC$(TP)
       ? "           the step increment was ";STP
       ? "          the number of steps was ";NOSTP
       ? "                    the color was ";COLOR
       ?

!!      ? A,B,TP,STP,NOSTP,COLOR
                               ! get new data or retain old
       ? "ENTER the radius of the fixed circle ";
               INPUT A
       ? "ENTER the radius of the rolling circle ";
               INPUT B
       IF TP=1 THEN TYPE$="E" ELSE TYPE$="H"
       ? "ENTER E)picycloid or H)ypocycloid ";
               INPUT TYPE$
       TYPE$=UCS(TYPE$)
       IF TYPE$="E" THEN TP=1 ELSE TP=2

       ? "ENTER the amount to increment the steps ";
               INPUT STP
       IF STP=0 THEN STP=1

       ? "ENTER the number of steps ";
               INPUT NOSTP
       IF NOSTP=0 THEN NOSTP=(5000*STP)

       ? "ENTER the color (0-63) ";
               INPUT COLOR
                               ! Write out the current data
       OPEN #1,"GEARS.DAT",OUTPUT
               ? #1,A,B,TP,STP,NOSTP,COLOR
               CLOSE #1
!!      ? A,B,TP,STP,NOSTP,COLOR
                               ! Clear the workstation & set color
       XCALL AMGSBR,G'CLRW,GCB,STATUS
       XCALL AMGSBR,G'SPLC,GCB,COLOR,STATUS
                               !turn off cursor
       PRINT TAB(-1,29);
       POINT'COUNT = 2
                       ! do the graph - plot the points & draw lines
PLOT:
       G=(A+B)/B
       H=(A-B)/B

       FOR Z=1 TO NOSTP STEP STP
               P=Z-1
               ON TP GOTO TP1, TP2
   TP1:
               X=(A+B)*COS(P) - B*COS(G*P)
               Y=(A+B)*SIN(P) - B*SIN(G*P)
               GOTO DRAW
   TP2:
               X=(A-B)*COS(P) + B*COS(H*P)
               Y=(A-B)*SIN(P) - B*SIN(H*P)
   DRAW:
                       ! move last ending points to starting points
               POINT'X(1)=X2 : POINT'Y(1)=Y2
               X2=FIX(X+XCNTR+.5)+XOFF : Y2=FIX(Y+YCNTR+.5)+YOFF
                       ! if first pass, don't draw, just load the values
               IF Z=1 THEN GOTO NXT
               POINT'X(2)=X2 : POINT'Y(2)=Y2
                       ! plot the line with the point array
               XCALL AMGSBR,G'PL,GCB,POINT'ARRAY,STATUS
   NXT:
       NEXT Z

END:
                       ! turn on cursor
       PRINT TAB(-1,28);
                       ! don't print control C message
       IF ERR(0)<>1 THEN ON ERROR GOTO 0
       END