Galton box animation: Difference between revisions

no edit summary
m (→‎{{header|Tcl}}: adjusted version requirement)
No edit summary
Line 759:
</pre>
There is a much more comprehensive solution to this on the [http://wiki.tcl.tk/8825 Tcler's Wiki].<!-- Too long to reproduce here -->
 
=={{header|XPL0}}==
 
This ''Peeks'' into some IBM-PC specific locations and hence is not entirely portable.
 
<lang XPL0>include c:\cxpl\codes; \intrinsic code declarations
define Balls = 80; \maximum number of balls
int Bx(Balls), By(Balls), \character cell coordinates of each ball
W, I, J, Peg, Dir;
[W:= Peek($40, $4A); \get screen width in characters
Clear; CrLf(6); CrLf(6);
for Peg:= 1 to 10 do \draw pegs
[for I:= 1 to 12-Peg do ChOut(6,^ ); \space over to first peg
for I:= 1 to Peg do [ChOut(6,^.); ChOut(6,^ )];
CrLf(6);
];
for J:= 0 to 12-1 do \draw slots
[for I:= 0 to 12-1 do [ChOut(6,^:); ChOut(6,^ )];
CrLf(6);
];
for I:= 0 to 23-1 do ChOut(6,^.); \draw bottom
for I:= 0 to Balls-1 do \make source of balls at top
[Bx(I):= 11; By(I):= 1];
Attrib($C); \make balls bright red
repeat \balls away! ...
for I:= 0 to Balls-1 do \for all the balls ...
[Cursor(Bx(I), By(I)); ChOut(6, ^ ); \erase ball's initial position
if Peek($B800, (Bx(I)+(By(I)+1)*W)*2) = ^ \is ball above empty location?
then By(I):= By(I)+1 \yes: fall straight down
else [Dir:= Ran(3)-1; \no: randomly fall right or left
if Peek($B800, (Bx(I)+Dir+(By(I)+1)*W)*2) = ^ then
[Bx(I):= Bx(I)+Dir; By(I):= By(I)+1];
];
Cursor(Bx(I), By(I)); ChOut(6, ^o); \draw ball at its new position
];
Sound(0, 3, 1); \delay about 1/6 second
until KeyHit; \continue until a key is struck
]</lang>
 
Example output:
<pre>
o
o.
.o.
. .o.
.o. . .
. .o. . .
. .o. . . .
. .o. . .o. .
. . .o. . . . .
. . . . . .o. . .
. . . . .o. .o. . .
: : : : : : : : : : : :
: : : : :o: : : : : : :
: : : :o: : : : : : : :
: : : : : : : : : : : :
: : : : :o: : : : : : :
: : : : : : : :o: : : :
: : : : : :o: : : : : :
: : :o: : :o: : : :o: :
: : : : : :o:o: : : : :
: : : : :o:o:o: : : : :
: : : : :o:o:o: : : : :
: : :o:o:o:o:o:o: : : :
.......................
</pre>
 
 
{{omit from|GUISS}}
772

edits