Anonymous user
Galton box animation: Difference between revisions
m
→{{header|REXX}}: changes "peg" to "pins", changed the (comment) title of the REXX program.
m (→{{header|REXX}}: used a better randomizer to provide a better spread.) |
m (→{{header|REXX}}: changes "peg" to "pins", changed the (comment) title of the REXX program.) |
||
Line 2,866:
The REXX version displays an ASCII version of a working Galton box.
Balls are dropped continuously
<br>pegs to fill the top <big><sup>1</sup>/<sub>3</sub></big> rows of the terminal screen.
<lang rexx>/*REXX pgm simulates Sir Francis Galton's box, aka: Galton Board, quincunx, bean machine*/
trace off /*suppress error messages from a HALT. */
signal on halt /*allow the user to halt the program.*/
Line 2,881 ⟶ 2,880:
sd= sd - 3 /*define the usable screen depth.*/
sw= sw - 1; if sw//2 then sw= sw -1 /* " " " odd " width.*/
if rows==0 then rows= (sw - 2 ) % 3 /*
clearScreen= 'CLS' /*the (OS) command to clear the screen.*/
ball = '☼' /* " " " " ball (bead).*/
call gen /*gen a triangle of
call run /*simulate a Galton box with some balls*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: @.=; do r=1 for rows; $= /*build a triangle of
if r//2 then iterate /* [↑] an empty odd row (with no
do
@.r= center( strip($, 'T'), sw) /*an easy method to build a triangle. */
end /*r*/; #= 0; return /*#: is the number of balls dropped. */
Line 2,911 ⟶ 2,910:
iterate /*go keep looking for balls.*/
end
if z==
if ?//2 then d= 1 /*if odd random#, fall right*/
if substr(@.n, y+d, 1)\==' ' then iterate /*blocked fall*/
|