Home » Archimedes archive » Archimedes World » AW-1995-02-Disc1.adf » Disk1Feb95 » !AWFeb95/Goodies/DrawBasic/!DrawBasic/Library/SpiroGraph

!AWFeb95/Goodies/DrawBasic/!DrawBasic/Library/SpiroGraph

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Archimedes World » AW-1995-02-Disc1.adf » Disk1Feb95
Filename: !AWFeb95/Goodies/DrawBasic/!DrawBasic/Library/SpiroGraph
Read OK:
File size: 0480 bytes
Load address: 0000
Exec address: 0000
File contents
REM SpiroGraph

R=10*(30+RND(10)) : r=10*(5+RND(10)) : m=r/FNgcd(R,r) : d=RND(r)
�SetUp
�Width(1)
�PathBegin(spiro)
FOR i=0 TO m*n
  IF i MOD n =0 THEN PRINT TAB(0,0);"                     ": PRINT TAB(0,0)"Number of turn="; m-(i DIV n)
 �Wheel(r,theta)
 NEXT
�PathEnd
�Quit

DEF �SetUp
�Inches
CIRCLE (FNDrawDx>>8)+640,(FNDrawDy>>8)+512,R
n=100 : c=COS(2*PI/n)     : s=SIN(2*PI/n)
        C=COS(R*2*PI/n/r) : S=SIN(R*2*PI/n/r)
�FrameSize(0,0,1280/180,1024/180)        
�FrameCoords(0,1280,0,1024)
�Origin(640,512)
ENDPROC

DEF �Wheel(r,theta)
IF i=0 THEN
 GCOL 3,11
 x_wheel=(R-r) : y_wheel=0
 x_hole=d      : y_hole=0
 CIRCLE (FNDrawDx>>8)+x_wheel+640,(FNDrawDy>>8)+y_wheel+512,r
ELSE
 GCOL 3,11
 xx=(FNDrawDx>>8)+x_wheel+640 : yy=(FNDrawDy>>8)+y_wheel+512
 CIRCLE xx,yy,r
 �Move(x_wheel+x_hole,y_wheel+y_hole)
 X=x_wheel*c-y_wheel*s : Y=x_wheel*s+y_wheel*c
 x_wheel=X : y_wheel=Y 
 X=x_hole*C+y_hole*S : Y=-x_hole*S+y_hole*C
 x_hole=X : y_hole=Y


  GCOL 11
 �Draw(x_wheel+x_hole,y_wheel+y_hole)
 WAIT
 GCOL 3,11

 CIRCLE (FNDrawDx>>8)+x_wheel+640,(FNDrawDy>>8)+y_wheel+512,r
 WAIT
ENDIF

ENDPROC


DEF �gcd(a,b)
IF b=0 THEN=a ELSE=�gcd(b,a MOD b)

00000000  52 45 4d 20 53 70 69 72  6f 47 72 61 70 68 0a 0a  |REM SpiroGraph..|
00000010  52 3d 31 30 2a 28 33 30  2b 52 4e 44 28 31 30 29  |R=10*(30+RND(10)|
00000020  29 20 3a 20 72 3d 31 30  2a 28 35 2b 52 4e 44 28  |) : r=10*(5+RND(|
00000030  31 30 29 29 20 3a 20 6d  3d 72 2f 46 4e 67 63 64  |10)) : m=r/FNgcd|
00000040  28 52 2c 72 29 20 3a 20  64 3d 52 4e 44 28 72 29  |(R,r) : d=RND(r)|
00000050  0a a0 53 65 74 55 70 0a  a0 57 69 64 74 68 28 31  |..SetUp..Width(1|
00000060  29 0a a0 50 61 74 68 42  65 67 69 6e 28 73 70 69  |)..PathBegin(spi|
00000070  72 6f 29 0a 46 4f 52 20  69 3d 30 20 54 4f 20 6d  |ro).FOR i=0 TO m|
00000080  2a 6e 0a 20 20 49 46 20  69 20 4d 4f 44 20 6e 20  |*n.  IF i MOD n |
00000090  3d 30 20 54 48 45 4e 20  50 52 49 4e 54 20 54 41  |=0 THEN PRINT TA|
000000a0  42 28 30 2c 30 29 3b 22  20 20 20 20 20 20 20 20  |B(0,0);"        |
000000b0  20 20 20 20 20 20 20 20  20 20 20 20 20 22 3a 20  |             ": |
000000c0  50 52 49 4e 54 20 54 41  42 28 30 2c 30 29 22 4e  |PRINT TAB(0,0)"N|
000000d0  75 6d 62 65 72 20 6f 66  20 74 75 72 6e 3d 22 3b  |umber of turn=";|
000000e0  20 6d 2d 28 69 20 44 49  56 20 6e 29 0a 20 a0 57  | m-(i DIV n). .W|
000000f0  68 65 65 6c 28 72 2c 74  68 65 74 61 29 0a 20 4e  |heel(r,theta). N|
00000100  45 58 54 0a a0 50 61 74  68 45 6e 64 0a a0 51 75  |EXT..PathEnd..Qu|
00000110  69 74 0a 0a 44 45 46 20  a0 53 65 74 55 70 0a a0  |it..DEF .SetUp..|
00000120  49 6e 63 68 65 73 0a 43  49 52 43 4c 45 20 28 46  |Inches.CIRCLE (F|
00000130  4e 44 72 61 77 44 78 3e  3e 38 29 2b 36 34 30 2c  |NDrawDx>>8)+640,|
00000140  28 46 4e 44 72 61 77 44  79 3e 3e 38 29 2b 35 31  |(FNDrawDy>>8)+51|
00000150  32 2c 52 0a 6e 3d 31 30  30 20 3a 20 63 3d 43 4f  |2,R.n=100 : c=CO|
00000160  53 28 32 2a 50 49 2f 6e  29 20 20 20 20 20 3a 20  |S(2*PI/n)     : |
00000170  73 3d 53 49 4e 28 32 2a  50 49 2f 6e 29 0a 20 20  |s=SIN(2*PI/n).  |
00000180  20 20 20 20 20 20 43 3d  43 4f 53 28 52 2a 32 2a  |      C=COS(R*2*|
00000190  50 49 2f 6e 2f 72 29 20  3a 20 53 3d 53 49 4e 28  |PI/n/r) : S=SIN(|
000001a0  52 2a 32 2a 50 49 2f 6e  2f 72 29 0a a0 46 72 61  |R*2*PI/n/r)..Fra|
000001b0  6d 65 53 69 7a 65 28 30  2c 30 2c 31 32 38 30 2f  |meSize(0,0,1280/|
000001c0  31 38 30 2c 31 30 32 34  2f 31 38 30 29 20 20 20  |180,1024/180)   |
000001d0  20 20 20 20 20 0a a0 46  72 61 6d 65 43 6f 6f 72  |     ..FrameCoor|
000001e0  64 73 28 30 2c 31 32 38  30 2c 30 2c 31 30 32 34  |ds(0,1280,0,1024|
000001f0  29 0a a0 4f 72 69 67 69  6e 28 36 34 30 2c 35 31  |)..Origin(640,51|
00000200  32 29 0a 45 4e 44 50 52  4f 43 0a 0a 44 45 46 20  |2).ENDPROC..DEF |
00000210  a0 57 68 65 65 6c 28 72  2c 74 68 65 74 61 29 0a  |.Wheel(r,theta).|
00000220  49 46 20 69 3d 30 20 54  48 45 4e 0a 20 47 43 4f  |IF i=0 THEN. GCO|
00000230  4c 20 33 2c 31 31 0a 20  78 5f 77 68 65 65 6c 3d  |L 3,11. x_wheel=|
00000240  28 52 2d 72 29 20 3a 20  79 5f 77 68 65 65 6c 3d  |(R-r) : y_wheel=|
00000250  30 0a 20 78 5f 68 6f 6c  65 3d 64 20 20 20 20 20  |0. x_hole=d     |
00000260  20 3a 20 79 5f 68 6f 6c  65 3d 30 0a 20 43 49 52  | : y_hole=0. CIR|
00000270  43 4c 45 20 28 46 4e 44  72 61 77 44 78 3e 3e 38  |CLE (FNDrawDx>>8|
00000280  29 2b 78 5f 77 68 65 65  6c 2b 36 34 30 2c 28 46  |)+x_wheel+640,(F|
00000290  4e 44 72 61 77 44 79 3e  3e 38 29 2b 79 5f 77 68  |NDrawDy>>8)+y_wh|
000002a0  65 65 6c 2b 35 31 32 2c  72 0a 45 4c 53 45 0a 20  |eel+512,r.ELSE. |
000002b0  47 43 4f 4c 20 33 2c 31  31 0a 20 78 78 3d 28 46  |GCOL 3,11. xx=(F|
000002c0  4e 44 72 61 77 44 78 3e  3e 38 29 2b 78 5f 77 68  |NDrawDx>>8)+x_wh|
000002d0  65 65 6c 2b 36 34 30 20  3a 20 79 79 3d 28 46 4e  |eel+640 : yy=(FN|
000002e0  44 72 61 77 44 79 3e 3e  38 29 2b 79 5f 77 68 65  |DrawDy>>8)+y_whe|
000002f0  65 6c 2b 35 31 32 0a 20  43 49 52 43 4c 45 20 78  |el+512. CIRCLE x|
00000300  78 2c 79 79 2c 72 0a 20  a0 4d 6f 76 65 28 78 5f  |x,yy,r. .Move(x_|
00000310  77 68 65 65 6c 2b 78 5f  68 6f 6c 65 2c 79 5f 77  |wheel+x_hole,y_w|
00000320  68 65 65 6c 2b 79 5f 68  6f 6c 65 29 0a 20 58 3d  |heel+y_hole). X=|
00000330  78 5f 77 68 65 65 6c 2a  63 2d 79 5f 77 68 65 65  |x_wheel*c-y_whee|
00000340  6c 2a 73 20 3a 20 59 3d  78 5f 77 68 65 65 6c 2a  |l*s : Y=x_wheel*|
00000350  73 2b 79 5f 77 68 65 65  6c 2a 63 0a 20 78 5f 77  |s+y_wheel*c. x_w|
00000360  68 65 65 6c 3d 58 20 3a  20 79 5f 77 68 65 65 6c  |heel=X : y_wheel|
00000370  3d 59 20 0a 20 58 3d 78  5f 68 6f 6c 65 2a 43 2b  |=Y . X=x_hole*C+|
00000380  79 5f 68 6f 6c 65 2a 53  20 3a 20 59 3d 2d 78 5f  |y_hole*S : Y=-x_|
00000390  68 6f 6c 65 2a 53 2b 79  5f 68 6f 6c 65 2a 43 0a  |hole*S+y_hole*C.|
000003a0  20 78 5f 68 6f 6c 65 3d  58 20 3a 20 79 5f 68 6f  | x_hole=X : y_ho|
000003b0  6c 65 3d 59 0a 0a 0a 20  20 47 43 4f 4c 20 31 31  |le=Y...  GCOL 11|
000003c0  0a 20 a0 44 72 61 77 28  78 5f 77 68 65 65 6c 2b  |. .Draw(x_wheel+|
000003d0  78 5f 68 6f 6c 65 2c 79  5f 77 68 65 65 6c 2b 79  |x_hole,y_wheel+y|
000003e0  5f 68 6f 6c 65 29 0a 20  57 41 49 54 0a 20 47 43  |_hole). WAIT. GC|
000003f0  4f 4c 20 33 2c 31 31 0a  0a 20 43 49 52 43 4c 45  |OL 3,11.. CIRCLE|
00000400  20 28 46 4e 44 72 61 77  44 78 3e 3e 38 29 2b 78  | (FNDrawDx>>8)+x|
00000410  5f 77 68 65 65 6c 2b 36  34 30 2c 28 46 4e 44 72  |_wheel+640,(FNDr|
00000420  61 77 44 79 3e 3e 38 29  2b 79 5f 77 68 65 65 6c  |awDy>>8)+y_wheel|
00000430  2b 35 31 32 2c 72 0a 20  57 41 49 54 0a 45 4e 44  |+512,r. WAIT.END|
00000440  49 46 0a 0a 45 4e 44 50  52 4f 43 0a 0a 0a 44 45  |IF..ENDPROC...DE|
00000450  46 20 bb 67 63 64 28 61  2c 62 29 0a 49 46 20 62  |F .gcd(a,b).IF b|
00000460  3d 30 20 54 48 45 4e 3d  61 20 45 4c 53 45 3d bb  |=0 THEN=a ELSE=.|
00000470  67 63 64 28 62 2c 61 20  4d 4f 44 20 62 29 0a 0a  |gcd(b,a MOD b)..|
00000480