home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1994-09-22 | 7.8 KB | 377 lines |
- >Spirograph
- BY Andy Pillidge
- icons%(4,8),linedata%(50,5)
- CDraw_initialise("Spirograph",1,&32000)
- readicondata
- 512,512
- 28,64,31,79,0
- toothsize%=12
- :teeth1%=192:teeth2%=80:colour%=7:hole%=3:starttooth%=0
- lines%=0
- file=
- rings%=
- setupmenu
- x%,y%,b%
- x%>=512
- rings%
- drawrings:rings%=
- x%<512
- rings%
- drawrings:rings%=
- (b%
- 5)<>0
- rings%
- drawrings:rings%=
- choice%=0
- yy%=1
- x%>=icons%(1,yy%)
- x%<=icons%(1,yy%)+48
- y%>=icons%(2,yy%)
- y%<=icons%(2,yy%)+32
- choice%=yy%
- x%>=512
- x%<=640
- y%>=392
- y%<=424
- choice%=9
- x%>=512
- x%<=768
- y%>=-512
- y%<=-256
- choice%=10
- x%>=512
- x%<=768
- y%>=328
- y%<=360
- choice%=11
- x%>=512
- x%<=640
- y%>=456
- y%<=488
- choice%=12
- (-1)
- (b%
- 1)<>0
- shift%=5
- shift%=1
- choice%
- ring(shift%)
- ring(-shift%)
- wheel(shift%)
- wheel(-shift%)
- hole(shift%)
- hole(-shift%)
- start(shift%)
- start(-shift%)
- drawline
- colsel
- clear
- drawfile
- drawfile
- lines%=0
- 0,21)"Make Drawfile:"'f$
- 0,21)
- 0,22)
- f$=""
- file=
- 0,0
- -512,-512,1024,1024
- 0,0
- l%=1
- lines%
- K}teeth1%=linedata%(l%,1):teeth2%=linedata%(l%,2):starttooth%=linedata%(l%,3):hole%=linedata%(l%,4):colour%=linedata%(l%,5)
- drawline
- CDraw_savefile(f$)
- file=
- drawline
- 0,colour%
- T"radius1=teeth1%*toothsize%/2/
- U"radius2=teeth2%*toothsize%/2/
- holeradius=radius2-hole%*8
- W&repts%=
- calcrepts(teeth1%,teeth2%)
- tooth%=starttooth%
- spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
- file
- CDraw_openpath(-1,colour%,0,0):
- CDraw_extendpath("MOVE "+
- (x2+512)+" "+
- (y2+512))
- 0,colour%:
- x2,y2
- loop%=1
- repts%
- n%=1
- teeth1%
- tooth%+=1
- spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
- 0,colour%:
- x2,y2
- file
- CDraw_extendpath("DRAW "+
- (x2+512)+" "+
- (y2+512))
- file
- CDraw_extendpath("CLOSE"):
- CDraw_closepath
- lines%+=1
- linedata%(lines%,1)=teeth1%:linedata%(lines%,2)=teeth2%:linedata%(lines%,3)=starttooth%:linedata%(lines%,4)=hole%::linedata%(lines%,5)=colour%
- spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
- m+angle1=(tooth%+starttooth%)/teeth1%*360
- angle2=tooth%/teeth2%*360
- angle3=angle1-angle2
- p-x1=radius1*
- (angle1)*(1-radius2/radius1)
- q-y1=radius1*
- (angle1)*(1-radius2/radius1)
- r1x2=x1+(radius2*
- (angle3)*holeradius/radius2)
- s1y2=y1+(radius2*
- (angle3)*holeradius/radius2)
- drawrings
- 3,63
- x"radius1=teeth1%*toothsize%/2/
- y"radius2=teeth2%*toothsize%/2/
- 0,0,radius1
- {"angle1=starttooth%/teeth1%*360
- |-x1=radius1*
- (angle1)*(1-radius2/radius1)
- }-y1=radius1*
- (angle1)*(1-radius2/radius1)
- x1,y1,radius2
- holeradius=radius2-hole%*8
- :x2=radius1*
- (angle1)*(1-(radius2-holeradius)/radius1)
- :y2=radius1*
- (angle1)*(1-(radius2-holeradius)/radius1)
- x2,y2,4
- calcrepts(teeth1%,teeth2%)
- n%+=1
- teeth1%*n%/teeth2%=
- (teeth1%*n%/teeth2%)
- ring(d%)
- teeth1%+=d%
- 4,8)teeth1%
- 4,20)teeth1%*
- calcrepts(teeth1%,teeth2%)
- teeth2%
- wheel(d%)
- teeth2%+=d%
- 4,11)teeth2%
- 4,20)teeth1%*
- calcrepts(teeth1%,teeth2%)
- teeth2%
- hole(d%)
- hole%+=d%
- 4,14)hole%
- 4,20)teeth1%*
- calcrepts(teeth1%,teeth2%)
- teeth2%
- start(d%)
- starttooth%+=d%
- 4,17)starttooth%
- 4,20)teeth1%*
- calcrepts(teeth1%,teeth2%)
- teeth2%
- colsel
- xc%=x%-512
- yc%=y%+512
- 3,63:
- (colour%
- 8)*32+512,(colour%
- 8)*32-480:
- #colour%=(xc%
- 32)*8+(yc%
- (colour%
- 8)*32+512,(colour%
- 8)*32-480:
- clear
- 0,0
- -512,-512,1024,1024
- lines%=0
- 0,0
- CDraw_reset
- setupmenu
- 0,7)"Ring size",
- 4,8)teeth1%
- 0,10)"Wheel size",
- 4,11)teeth2%
- 0,13)"Hole number",
- 4,14)hole%
- 0,16)"Start tooth",
- 4,17)starttooth%
- 0,19)"Points",
- 4,20)teeth1%*
- calcrepts(teeth1%,teeth2%)
- teeth2%
- 3,56
- y%=1
- icons%(1,y%),icons%(2,y%),48,28
- icons%(1,y%)+16,icons%(2,y%)+31:
- (138+(y%-1)
- 512,392,128,32
- 544,424:
- "Draw"
- 3,12
- 512,328,128,32
- 544,360:
- "Clear"
- 3,42
- 512,456,128,32
- 544,488:
- "File"
- x%=0
- y%=0
- x%*8+y%
- (x%*32)+512,(y%*32)-512,24,24
- 3,63:
- (colour%
- 8)*32+512,(colour%
- 8)*32-480:
- 143:
- readicondata
- Y%=1
- X%=1
- icons%(X%,Y%)
- 512,224
- 512,128
- 512,32
- 512,-64
- 672,224
- 672,128
- 672,32
- 672,-64
- CDraw_initialise(appl_name$, nfonts%, size%)
- _buffer% size%
- _ptr%=_buffer%
- %$_ptr%=
- "Draw"+
- (0)),12)
- _ptr%+=12
- #$_ptr%=
- appl_name$+
- 12," "),12)
- CDraw_font$(nfonts%+1), _colours% 20*4, _dash$(4)
- "Wimp_ReadPalette",,_colours%
- _dash$(1)=
- _dash$(2)=
- _dash$(3)=
- *_dash$(4)=
- _flags%=&20100042
- CDraw_reset
- _flags%=&20100042
- CDraw_nofill%=-1
- CDraw%=
- CDraw_reset
- _ptr%=_buffer%+40
- _olx%=1<<30:_oby%=1<<30
- _orx%=0:_oty%=0
- CDraw_savefile(f$)
- CDraw%
- _buffer%!24=_olx%
- _buffer%!28=_oby%
- _buffer%!32=_orx%
- _buffer%!36=_oty%
- "OS_File",10,f$,&AFF,,_buffer%,_ptr%
- _colour(c%)
- c%>=0
- =((c%
- &03)*80+((c%>>2)
- &03)*80*&100+((c%>>4)
- &03)*80*&10000)<<8
- IF c%>=0 THEN =!(_colours%+c%*4) AND &FFFFFF00 ELSE =-1
- _checkspace(lx%,by%,rx%,ty%)
- lx%<_olx%
- _olx%=lx%
- by%<_oby%
- _oby%=by%
- rx%>_orx%
- _orx%=rx%
- ty%>_oty%
- _oty%=ty%
- _putword(W%)
- !_ptr%=W%
- _ptr%+=4
- _putwords(X%,Y%)
- X%=X%<<8:Y%=Y%<<8
- X%<_start%!8
- _start%!8 =X%
- Y%<_start%!12
- _start%!12 =Y%
- X%>_start%!16
- _start%!16 =X%
- Y%>_start%!20
- _start%!20=Y%
- _putword(X%):
- _putword(Y%)
- _putcoords(_start%, lx%, by%, rx%, ty%)
- _start%!0=lx%<<8
- _start%!4=by%<<8
- _start%!8=rx%<<8
- _start%!12=ty%<<8
- CDraw_pathobject(fill%, col%, thick%, dash%, path$)
- CDraw_openpath(fill%, col%, thick%, dash%)
- CDraw_extendpath(path$)
- CDraw_closepath
- CDraw_openpath(fill%, col%, thick%, dash%)
- CDraw%
- pattern$,I%
- _start%=_ptr%
- _putword(2)
- _ptr%+=20
- _putcoords(_start%+8,1<<30,1<<30,0,0)
- _putword(
- _colour(fill%))
- _putword(
- _colour(col%))
- _putword(thick%<<8)
- _putword(_flags%
- &80*-(dash%<>0))
- dash%>0
- pattern$=_dash$(dash%)
- _putword(0)
- _putword(
- pattern$/4)
- I%=1
- pattern$
- ?_ptr%=
- pattern$,I%,1)
- _ptr%+=1
- CDraw_extendpath(path$)
- _pathtype%,I%
- path$<>""
- _nextchunk(path$)
- "MOVE" :_pathtype%=2
- "CGAP" :_pathtype%=4
- "CLOSE" :_pathtype%=5
- "CURVE" :_pathtype%=6
- "GAP" :_pathtype%=7
- "DRAW" :_pathtype%=8
- _pathtype%<>0
- _putword(_pathtype%)
- _pathtype%
- 2,3,7,8:
- _putpair(path$)
- I%=1
- _putpair(path$)
- CDraw_closepath
- _putword(0)
- _start%!4=_ptr%-_start%
- _checkspace(_start%!8, _start%!12, _start%!16, _start%!20)
- _nextchunk(
- path$)
- P%,chunk$
- path$+" "," ")
- h$chunk$=
- path$,
- path$+" "," ")-1)
- path$=
- path$,P%+1)
- =chunk$
- _putpair(
- path$)
- X%,Y%
- _nextchunk(path$)
- _nextchunk(path$)
- _putwords(X%,Y%)
-