Galton box animation: Difference between revisions

no edit summary
(Added Go)
No edit summary
Line 3,105:
.......................
</pre>
 
=={{header|Yabasic}}==
<lang Yabasic>bola$ = "0000ff"
obst$ = "000000"
 
maxBalls = 10
cx = 1
cy = 2
dim Balls(maxBalls, 2)
 
open window 600,600
window origin "ct"
 
maxh = peek("winheight")
 
REM Draw the pins:
 
FOR row = 1 TO 7
FOR col = 1 TO row
FILL circle 40*col - 20*row, 40*row+80, 10
NEXT col
NEXT row
 
REM Animate
tick = 0
bolas = 0
color 0,0,255
 
do
if (bolas < maxBalls) then
if tick = 3 then
tick = 0
bolas = bolas + 1
Balls(bolas, cx) = 20
Balls(bolas, cy) = 10
end if
tick = tick + 1
end if
for n = 1 to bolas
if Balls(n, cy) then
color$ = right$(getbit$(Balls(n,cx),Balls(n,cy) + 10,Balls(n,cx),Balls(n,cy) + 10),6)
if (color$ = bola$) or (Balls(n,cy) >= maxh - 15) then
Balls(n,cy) = 0
break
end if
clear fill circle Balls(n,cx),Balls(n,cy),10
if color$ = obst$ then
if int(ran(2)) then
Balls(n,cx) = Balls(n,cx) - 20
else
Balls(n,cx) = Balls(n,cx) + 20
end if
end if
Balls(n,cy) = Balls(n,cy)+10
fill circle Balls(n,cx),Balls(n,cy),10
wait .001
else
wait .001
end if
next n
loop
</lang>
672

edits