home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / general / progs / spirograph / Spirograph (.txt) < prev   
Encoding:
RISC OS BBC BASIC V Source  |  1994-09-22  |  7.8 KB  |  377 lines

  1.  >Spirograph
  2.  BY Andy Pillidge
  3.  icons%(4,8),linedata%(50,5)
  4. CDraw_initialise("Spirograph",1,&32000)
  5. readicondata
  6.  512,512
  7.  28,64,31,79,0
  8. toothsize%=12
  9. :teeth1%=192:teeth2%=80:colour%=7:hole%=3:starttooth%=0
  10. lines%=0
  11. file=
  12. rings%=
  13. setupmenu
  14.  x%,y%,b%
  15.  x%>=512 
  16.  rings% 
  17. drawrings:rings%=
  18.  x%<512 
  19.  rings% 
  20. drawrings:rings%=
  21.  (b% 
  22.  5)<>0
  23.  rings% 
  24. drawrings:rings%=
  25. choice%=0
  26.  yy%=1 
  27.  x%>=icons%(1,yy%) 
  28.  x%<=icons%(1,yy%)+48 
  29.  y%>=icons%(2,yy%) 
  30.  y%<=icons%(2,yy%)+32 
  31.  choice%=yy%
  32.  x%>=512 
  33.  x%<=640 
  34.  y%>=392 
  35.  y%<=424 
  36.  choice%=9
  37.  x%>=512 
  38.  x%<=768 
  39.  y%>=-512 
  40.  y%<=-256 
  41.  choice%=10
  42.  x%>=512 
  43.  x%<=768 
  44.  y%>=328 
  45.  y%<=360 
  46.  choice%=11
  47.  x%>=512 
  48.  x%<=640 
  49.  y%>=456 
  50.  y%<=488 
  51.  choice%=12
  52. (-1) 
  53.  (b% 
  54.  1)<>0 
  55.  shift%=5 
  56.  shift%=1
  57.  choice% 
  58. ring(shift%)
  59. ring(-shift%)
  60. wheel(shift%)
  61. wheel(-shift%)
  62. hole(shift%)
  63. hole(-shift%)
  64. start(shift%)
  65. start(-shift%)
  66. drawline
  67. colsel
  68. clear
  69. drawfile
  70. drawfile
  71.  lines%=0 
  72. 0,21)"Make Drawfile:"'f$
  73. 0,21)
  74. 0,22)
  75.  f$="" 
  76. file=
  77.  0,0 
  78.  -512,-512,1024,1024
  79.  0,0 
  80.  l%=1 
  81.  lines%
  82. K}teeth1%=linedata%(l%,1):teeth2%=linedata%(l%,2):starttooth%=linedata%(l%,3):hole%=linedata%(l%,4):colour%=linedata%(l%,5)
  83. drawline
  84. CDraw_savefile(f$)
  85. file=
  86. drawline
  87.  0,colour%
  88. T"radius1=teeth1%*toothsize%/2/
  89. U"radius2=teeth2%*toothsize%/2/
  90. holeradius=radius2-hole%*8
  91. W&repts%=
  92. calcrepts(teeth1%,teeth2%)
  93. tooth%=starttooth%
  94. spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
  95.  file 
  96. CDraw_openpath(-1,colour%,0,0):
  97. CDraw_extendpath("MOVE "+
  98. (x2+512)+" "+
  99. (y2+512))
  100.  0,colour%:
  101.  x2,y2
  102.  loop%=1 
  103.  repts%
  104.  n%=1 
  105.  teeth1%
  106. tooth%+=1
  107. spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
  108.  0,colour%:
  109.  x2,y2
  110.  file 
  111. CDraw_extendpath("DRAW "+
  112. (x2+512)+" "+
  113. (y2+512))
  114.  file 
  115. CDraw_extendpath("CLOSE"):
  116. CDraw_closepath
  117. lines%+=1
  118. linedata%(lines%,1)=teeth1%:linedata%(lines%,2)=teeth2%:linedata%(lines%,3)=starttooth%:linedata%(lines%,4)=hole%::linedata%(lines%,5)=colour%
  119. spiro(tooth%,teeth1%,teeth2%,holeradius,colour%)
  120. m+angle1=(tooth%+starttooth%)/teeth1%*360
  121. angle2=tooth%/teeth2%*360
  122. angle3=angle1-angle2
  123. p-x1=radius1*
  124. (angle1)*(1-radius2/radius1)
  125. q-y1=radius1*
  126. (angle1)*(1-radius2/radius1)
  127. r1x2=x1+(radius2*
  128. (angle3)*holeradius/radius2)
  129. s1y2=y1+(radius2*
  130. (angle3)*holeradius/radius2)
  131. drawrings
  132.  3,63
  133. x"radius1=teeth1%*toothsize%/2/
  134. y"radius2=teeth2%*toothsize%/2/
  135.  0,0,radius1
  136. {"angle1=starttooth%/teeth1%*360
  137. |-x1=radius1*
  138. (angle1)*(1-radius2/radius1)
  139. }-y1=radius1*
  140. (angle1)*(1-radius2/radius1)
  141.  x1,y1,radius2
  142. holeradius=radius2-hole%*8
  143. :x2=radius1*
  144. (angle1)*(1-(radius2-holeradius)/radius1)
  145. :y2=radius1*
  146. (angle1)*(1-(radius2-holeradius)/radius1)
  147.  x2,y2,4
  148. calcrepts(teeth1%,teeth2%)
  149.     n%+=1
  150.  teeth1%*n%/teeth2%=
  151. (teeth1%*n%/teeth2%)
  152. ring(d%)
  153. teeth1%+=d%
  154. 4,8)teeth1%
  155. 4,20)teeth1%*
  156. calcrepts(teeth1%,teeth2%) 
  157.  teeth2%
  158. wheel(d%)
  159. teeth2%+=d%
  160. 4,11)teeth2%
  161. 4,20)teeth1%*
  162. calcrepts(teeth1%,teeth2%) 
  163.  teeth2%
  164. hole(d%)
  165. hole%+=d%
  166. 4,14)hole%
  167. 4,20)teeth1%*
  168. calcrepts(teeth1%,teeth2%) 
  169.  teeth2%
  170. start(d%)
  171. starttooth%+=d%
  172. 4,17)starttooth%
  173. 4,20)teeth1%*
  174. calcrepts(teeth1%,teeth2%) 
  175.  teeth2%
  176. colsel
  177. xc%=x%-512
  178. yc%=y%+512
  179.  3,63:
  180.  (colour% 
  181.  8)*32+512,(colour% 
  182.  8)*32-480:
  183. #colour%=(xc% 
  184.  32)*8+(yc% 
  185.  (colour% 
  186.  8)*32+512,(colour% 
  187.  8)*32-480:
  188. clear
  189.  0,0 
  190.  -512,-512,1024,1024
  191. lines%=0
  192.  0,0 
  193. CDraw_reset
  194. setupmenu
  195. 0,7)"Ring size",
  196. 4,8)teeth1%
  197. 0,10)"Wheel size",
  198. 4,11)teeth2%
  199. 0,13)"Hole number",
  200. 4,14)hole%
  201. 0,16)"Start tooth",
  202. 4,17)starttooth%
  203. 0,19)"Points",
  204. 4,20)teeth1%*
  205. calcrepts(teeth1%,teeth2%) 
  206.  teeth2%
  207.  3,56
  208.  y%=1 
  209.  icons%(1,y%),icons%(2,y%),48,28
  210.  icons%(1,y%)+16,icons%(2,y%)+31:
  211. (138+(y%-1)
  212.  512,392,128,32
  213.  544,424:
  214. "Draw"
  215.  3,12
  216.  512,328,128,32
  217.  544,360:
  218. "Clear"
  219.  3,42
  220.  512,456,128,32
  221.  544,488:
  222. "File"
  223.  x%=0 
  224.  y%=0 
  225.  x%*8+y% 
  226.  (x%*32)+512,(y%*32)-512,24,24
  227.  3,63:
  228.  (colour% 
  229.  8)*32+512,(colour% 
  230.  8)*32-480:
  231.  143:
  232. readicondata
  233.  Y%=1 
  234.  X%=1 
  235.  icons%(X%,Y%)
  236.  512,224
  237.  512,128
  238.  512,32
  239.  512,-64
  240.  672,224
  241.  672,128
  242.  672,32
  243.  672,-64
  244. CDraw_initialise(appl_name$, nfonts%, size%)
  245.  _buffer% size%
  246. _ptr%=_buffer%
  247. %$_ptr%=
  248. "Draw"+
  249. (0)),12)
  250. _ptr%+=12
  251. #$_ptr%=
  252. appl_name$+
  253. 12," "),12)
  254.  CDraw_font$(nfonts%+1), _colours% 20*4, _dash$(4)
  255. "Wimp_ReadPalette",,_colours%
  256. _dash$(1)=
  257. _dash$(2)=
  258. _dash$(3)=
  259. *_dash$(4)=
  260. _flags%=&20100042
  261. CDraw_reset
  262. _flags%=&20100042
  263. CDraw_nofill%=-1
  264. CDraw%=
  265. CDraw_reset
  266. _ptr%=_buffer%+40
  267. _olx%=1<<30:_oby%=1<<30
  268. _orx%=0:_oty%=0
  269. CDraw_savefile(f$)
  270.  CDraw% 
  271. _buffer%!24=_olx%
  272. _buffer%!28=_oby%
  273. _buffer%!32=_orx%
  274. _buffer%!36=_oty%
  275. "OS_File",10,f$,&AFF,,_buffer%,_ptr%
  276. _colour(c%)
  277.  c%>=0 
  278.  =((c%
  279. &03)*80+((c%>>2)
  280. &03)*80*&100+((c%>>4)
  281. &03)*80*&10000)<<8 
  282.   IF c%>=0 THEN =!(_colours%+c%*4) AND &FFFFFF00 ELSE =-1
  283. _checkspace(lx%,by%,rx%,ty%)
  284.  lx%<_olx% 
  285.  _olx%=lx%
  286.  by%<_oby% 
  287.  _oby%=by%
  288.  rx%>_orx% 
  289.  _orx%=rx%
  290.  ty%>_oty% 
  291.  _oty%=ty%
  292. _putword(W%)
  293. !_ptr%=W%
  294. _ptr%+=4
  295. _putwords(X%,Y%)
  296. X%=X%<<8:Y%=Y%<<8
  297.  X%<_start%!8 
  298.  _start%!8 =X%
  299.  Y%<_start%!12 
  300.  _start%!12 =Y%
  301.  X%>_start%!16 
  302.  _start%!16 =X%
  303.  Y%>_start%!20 
  304.  _start%!20=Y%
  305. _putword(X%):
  306. _putword(Y%)
  307. _putcoords(_start%, lx%, by%, rx%, ty%)
  308. _start%!0=lx%<<8
  309. _start%!4=by%<<8
  310. _start%!8=rx%<<8
  311. _start%!12=ty%<<8
  312. CDraw_pathobject(fill%, col%, thick%, dash%, path$)
  313. CDraw_openpath(fill%, col%, thick%, dash%)
  314. CDraw_extendpath(path$)
  315. CDraw_closepath
  316. CDraw_openpath(fill%, col%, thick%, dash%)
  317.  CDraw% 
  318.  pattern$,I%
  319. _start%=_ptr%
  320. _putword(2)
  321. _ptr%+=20
  322. _putcoords(_start%+8,1<<30,1<<30,0,0)
  323. _putword(
  324. _colour(fill%))
  325. _putword(
  326. _colour(col%))
  327. _putword(thick%<<8)
  328. _putword(_flags% 
  329.  &80*-(dash%<>0))
  330.  dash%>0 
  331. pattern$=_dash$(dash%)
  332. _putword(0)
  333. _putword(
  334. pattern$/4)
  335.  I%=1 
  336. pattern$
  337. ?_ptr%=
  338. pattern$,I%,1)
  339. _ptr%+=1
  340. CDraw_extendpath(path$)
  341.  _pathtype%,I%
  342.  path$<>""
  343. _nextchunk(path$) 
  344.  "MOVE" :_pathtype%=2
  345.  "CGAP" :_pathtype%=4
  346.  "CLOSE" :_pathtype%=5
  347.  "CURVE" :_pathtype%=6
  348.  "GAP" :_pathtype%=7
  349.  "DRAW" :_pathtype%=8
  350.  _pathtype%<>0 
  351. _putword(_pathtype%)
  352.  _pathtype% 
  353.  2,3,7,8:
  354. _putpair(path$)
  355.  I%=1 
  356. _putpair(path$)
  357. CDraw_closepath
  358. _putword(0)
  359. _start%!4=_ptr%-_start%
  360. _checkspace(_start%!8, _start%!12, _start%!16, _start%!20)
  361. _nextchunk(
  362.  path$)
  363.  P%,chunk$
  364. path$+" "," ")
  365. h$chunk$=
  366. path$,
  367. path$+" "," ")-1)
  368. path$=
  369. path$,P%+1)
  370. =chunk$
  371. _putpair(
  372.  path$)
  373.  X%,Y%
  374. _nextchunk(path$)
  375. _nextchunk(path$)
  376. _putwords(X%,Y%)
  377.