home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / education / a / juggling / !Jugglin27 / !RunImage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1994-10-07  |  8KB  |  381 lines

  1.  >!RunImage
  2.  !Juggling
  3.  by Nick Craig-Wood
  4.  This juggles patterns in the Cambridge Jugglers Association
  5.  standard juggling format
  6.  starting hand is right hand = 0
  7.  28: 
  8.  27: 
  9. !*Print <Juggling$Dir>.WimpPal
  10. screeny%=960: screenx%=1280
  11. resetbanks
  12. error
  13. %bally%=screeny%/40: ballx%=bally%
  14. rhand%=ballx%*4
  15. (lx%=0.25*screenx%: rx%=0.75*screenx%
  16. $lx0%=lx%+rhand%: lx1%=lx%-rhand%
  17. $rx0%=rx%-rhand%: rx1%=rx%+rhand%
  18. midx%=0.5*screenx%
  19. chesty%=0.7*screeny%
  20. shoulderx%=0.15*screenx%
  21. shouldery%=0.65*screeny%
  22. elbowx%=0.25*screenx%
  23. elbowy%=0.37*screeny%
  24. headd%=0.12*screeny%
  25. heady%=screeny%-headd%
  26. bottomy%=0
  27. heighty%=0.8*screeny%
  28. basey%=rhand%+bally%
  29. rtick%=32
  30. tickspeed%=2
  31. nmax%=250
  32.  pattern%(nmax%)   :
  33.  pattern
  34.  height%(9)        :
  35.  height of throw
  36.  ticks%(9)         :
  37.  current position of throw
  38.  hands%(9)         :
  39.  starting hand
  40.  pos%(9)           :
  41.  position in pattern ball was thrown
  42.  trackx%(9,rtick%*9)
  43.  tracky%(9,rtick%*9)
  44.  handx%(1,2*rtick%)
  45.  handy%(1,2*rtick%)
  46. r2%=2*rtick%
  47. SpriteAreaSize=64*1024
  48.  SpriteArea SpriteAreaSize
  49.  sprite%(9)
  50. SpriteArea!0=SpriteAreaSize
  51. SpriteArea!8=16
  52. SpriteOp=&2E
  53.  SpriteOp,9+256,SpriteArea
  54.  SpriteOp,10+256,SpriteArea,"JugSprites"
  55.  i%=1 
  56.  SpriteOp,24+256,SpriteArea,"ball"+
  57. (i%) 
  58.  ,,sprite%(i%-1)
  59.  possible attributes
  60. getpattern
  61.  "Computing throws ... ";
  62. track
  63. juggle
  64. getpattern
  65. 0,1);
  66.  "Whilst the program is juggling"
  67.  "  + speeds it up"
  68.  "  - slows it down"
  69.  "and SPACE enters another pattern"
  70. O8  prompt$="Enter Pattern (Q to Quit E for Examples)"
  71.  prompt$
  72.     ok=
  73. U7    
  74. p$>nmax% 
  75.  "Pattern too big": ok=
  76. : p$="3"
  77.     plen%=0
  78.  i%=1 
  79.       a$=
  80. p$,i%,1)
  81.       
  82. Z6        
  83.  "0","1","2","3","4","5","6","7","8","9":
  84. [&          pattern%(plen%)=
  85.           plen%+=1
  86.         
  87.  "Q","q"
  88.           
  89.         
  90.  "E","e"
  91.           
  92. showexamples
  93.           
  94.  prompt$
  95.           ok=
  96.         
  97. d+          
  98.  "Unrecognised command: ";a$
  99.           ok=
  100.       
  101.  plen%=0 
  102.       pattern%(0)=3
  103.       plen%=1
  104. l        
  105.  (plen% 
  106.       
  107.  2*plen%>nmax% 
  108.         
  109.  "Pattern too big"
  110.         ok=
  111.       
  112.         
  113.  i%=0 
  114.  plen%-1
  115. t-          pattern%(plen%+i%)=pattern%(i%)
  116.         
  117.         plen%=2*plen%
  118.       
  119. x        
  120.     func=0
  121.  func<>-1 
  122.       func+=1
  123.       
  124.  func 
  125.         
  126.  1: ok=
  127. getsum
  128.         
  129.  2: ok=
  130. getav
  131.         
  132.  3: ok=
  133. validpat
  134.         
  135. : func=-1
  136.       
  137.         
  138.  max%>1 
  139. 0    yscale=heighty%/0.25/((max%-1)*(max%-1))
  140.     yscale=heighty%
  141. showexamples
  142.  "Example patterns"
  143.  "0 - 9 cascade 0 - 9 balls"
  144.  "31,51,71,91 shower 2,3,4,5 balls"
  145.  "How to learn to juggle 3 balls"
  146.  "300, 3302, 2330, 330, 333"
  147.  "How to learn to juggle 4 balls"
  148.  "423, 40, 04, 4440, 441, 4"
  149.  "How to learn to juggle 5 balls"
  150.  "51, 15, 55500, 50505, 552, 55550, 5"
  151.  "Some other interesting patterns"
  152.  "423, 55500, 51, 531, 504, 612"
  153.  "71, 53444, 53, 633, 552, 55550, 5551"
  154.  "3333333334515151515141"
  155.  "Fun, but impossible"
  156.  "123456789, 97531, 678, 747"
  157. getsum
  158.   ok=
  159.   sum=0: max%=-1
  160.  i%=0 
  161.  plen%-1
  162.     a%=pattern%(i%)
  163.     sum+=a%
  164.  a%>max% 
  165.  max%=a%
  166. getav
  167.   ok=
  168.   nb=sum/plen%
  169. (nb)<>0 
  170. )    
  171.  "Pattern was for ";nb;" balls!"
  172.     ok=
  173.   nball%=
  174. validpat
  175.   ok=
  176.  plen%>1 
  177.  i%=0 
  178.  plen%-2
  179.       
  180.  j%=i%+1 
  181.  plen%-1
  182. 4        
  183.  pattern%(i%)+i%=pattern%(j%)+j% 
  184.       
  185. B    
  186.  "Pattern involved catching more than one ball at a time"
  187. juggle
  188.   height%()=-1
  189.   ticks%()=0
  190.   p%=-1
  191.   hand%=0
  192.     dtick=1/rtick%
  193.         
  194.       
  195. tickjuggle
  196.       hand%=1-hand%
  197.       a$=
  198.  a$<>""
  199.     mego=
  200.         
  201.       
  202. #        tickspeed%=2*tickspeed%
  203. 3        
  204.  tickspeed%>rtick% 
  205.  tickspeed%=rtick%
  206.       
  207. #        tickspeed%=tickspeed%/2
  208. )        
  209.  tickspeed%<1 
  210.  tickspeed%=1
  211.       
  212.  " ": mego=
  213.       
  214.  "Q","q": 
  215.         
  216.     a$=
  217.  a$="" 
  218.  mego
  219.  mego
  220. tickjuggle
  221.   p%=(p%+1) 
  222.  plen%
  223.   h%=pattern%(p%)
  224.   ticks%()=ticks%()+rtick%
  225.  h%>0 
  226. E    
  227.  find out which ball has landed, and throw a new one if nec.
  228.     b%=-1: c%=-1
  229.  i%=0 
  230.  nball%-1
  231. ,      
  232.  ticks%(i%)>=rtick%*height%(i%) 
  233. ,        
  234.  height%(i%)>=0 
  235.  b%=i% 
  236.  c%=i%
  237.       
  238.  b%=-1 
  239.  b%=c%
  240.  b%<>-1 
  241.       height%(b%)=h%
  242.       ticks%(b%)=0
  243.       pos%(b%)=p%
  244.       hands%(b%)=hand%
  245.         
  246.  ptick%=0 
  247.  rtick%-1 
  248.  tickspeed%
  249. startupdate
  250.  128+0
  251.         
  252.     d%=rhand%/2
  253.     t%=ptick%+rtick%*hand%
  254. ?    
  255.  midx%-elbowx%,elbowy%, handx%(1,t%),handy%(1,t%)-d%/2
  256. ?    
  257.  midx%+elbowx%,elbowy%, handx%(0,t%),handy%(0,t%)-d%/2
  258. <    
  259.  midx%-elbowx%,elbowy%, midx%-shoulderx%,shouldery%
  260. <    
  261.  midx%+elbowx%,elbowy%, midx%+shoulderx%,shouldery%
  262. 4    
  263.  midx%-shoulderx%,shouldery%, midx%,chesty%
  264. 4    
  265.  midx%+shoulderx%,shouldery%, midx%,chesty%
  266. -    
  267.  midx%,heady%-headd%, midx%,bottomy%
  268.  midx%,heady%,headd%
  269.  i%=0 
  270.  nball%-1
  271.       
  272.  height%(i%)>=0 
  273.          t%=ticks%(i%)+ptick%
  274.         h%=height%(i%)
  275.         x%=trackx%(h%,t%)
  276.         y%=tracky%(h%,t%)
  277. )        
  278.  hands%(i%) 
  279.  x%=screenx%-x%
  280. C        
  281.  SpriteOp,34+512,SpriteArea,sprite%(i%),x%-48,y%-24,8
  282.       
  283. endupdate
  284.  ptick%
  285.  This makes the tracks for the hands and the balls
  286. track
  287.  first track the hands
  288.  ptick%=0 
  289.  r2%-1
  290.     t=
  291. *ptick%/rtick%
  292. )(    handx%(0,ptick%)=rx%-rhand%*
  293. *+    handy%(0,ptick%)=basey%-rhand%*
  294. +(    handx%(1,ptick%)=lx%-rhand%*
  295. ,+    handy%(1,ptick%)=basey%+rhand%*
  296.  ptick%
  297.  now make each ball track
  298.  p%=1 
  299. (p%)) 
  300.  ;p%;
  301.     sh%=0
  302.     h%=p%
  303. 6(    
  304.  (h% 
  305.  fh%=1-sh% 
  306.  fh%=sh%
  307. 8D    
  308.  This makes the tracks for throw from sh% to fh%, height h%
  309.  In position p%
  310.  h%>1 
  311.       k0%=rtick%/2
  312. =(      k1%=(h%*rtick%-rtick%/2) 
  313. >        
  314.       k0%=0
  315.       k1%=rtick%
  316. A        
  317. B0    sx%=handx%(sh%,k0%): sy%=handy%(sh%,k0%)
  318. C0    fx%=handx%(fh%,k1%): fy%=handy%(fh%,k1%)
  319.  3,4,5,6,7,8,9:
  320. H"      
  321.  ptick%=0 
  322.  h%*rtick%-1
  323.         ti=ptick%/rtick%
  324.         q%=ptick% 
  325.         
  326.  ti<0.5 
  327.           x%=handx%(sh%,q%)
  328.           y%=handy%(sh%,q%)
  329.         
  330.           
  331.  ti>h%-0.5 
  332. P!            x%=handx%(fh%,q%)
  333. Q!            y%=handy%(fh%,q%)
  334.           
  335. S!            t=(ti-0.5)/(h%-1)
  336. T?            y%=(fy%-sy%)*t+sy%+yscale*t*(1-t)*(h%-1)*(h%-1)
  337. U"            x%=(fx%-sx%)*t+sx%
  338.           
  339.         
  340. X!        trackx%(p%,ptick%)=x%
  341. Y!        tracky%(p%,ptick%)=y%
  342.       
  343.  ptick%
  344. ]"      
  345.  ptick%=0 
  346.  h%*rtick%-1
  347. ^1        trackx%(p%,ptick%)=handx%(sh%,ptick%)
  348. _1        tracky%(p%,ptick%)=handy%(sh%,ptick%)
  349.       
  350.  ptick%
  351.       
  352.  ptick%=0 
  353.  rtick%-1
  354.         t=ptick%/rtick%
  355. e.        trackx%(p%,ptick%)=(fx%-sx%)*t+sx%
  356. f?        tracky%(p%,ptick%)=(fy%-sy%)*t+sy%+2*yscale*t*(1-t)
  357.       
  358.  ptick%
  359. i        
  360. error
  361. resetbanks
  362.  "*** Error ***"
  363.  " at ";
  364. resetbanks
  365.  "OS_Byte",19        :
  366.  wait for Vsync
  367.  "OS_Byte",112,0     :
  368.  reset logical bank
  369.  "OS_Byte",113,0     :
  370.  reset physical bank
  371.   bank%=1
  372. startupdate
  373.   bank%=3-bank%
  374.  "OS_Byte",112,bank% :
  375.  change logical bank
  376. endupdate
  377.  "OS_Byte",19        :
  378.  wait for Vsync
  379.  "OS_Byte",113,bank% :
  380.  change physical bank
  381.