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   (up to a number specified or the default),   the default is enough rows of
<br>pegs to fill the top &nbsp; <big><sup>1</sup>/<sub>3</sub></big> &nbsp; rows of the terminal screen.
<lang rexx>/*REXX pgm simulates Sir Francis Galton's box, aka: Galton Board, quincunx, bean machine*/
<br>Collisions are handled by suspending the falling ball(s) until the blocking ball(s) drop down &nbsp; (out of the path).
<lang rexx>/*REXX program to simulate a Galton box (aka, Sir Francis Galton's device). */
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 /*pegspins are on the first third of screen*/
clearScreen= 'CLS' /*the (OS) command to clear the screen.*/
pegpin = '·' /*define character for a pegpin (pin). */
ball = '☼' /* " " " " ball (bead).*/
call gen /*gen a triangle of pegspins with some rows*/
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 pegspins for the box.*/
if r//2 then iterate /* [↑] an empty odd row (with no pegspins)*/
do pegspins=1 for r%2; $= $ pegpin; end /*pegspins*/ /*build a row of pegspins.*/
@.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==pegpin then do; ?= random(,999); d= -1 /*assume falling to the left*/
if ?//2 then d= 1 /*if odd random#, fall right*/
if substr(@.n, y+d, 1)\==' ' then iterate /*blocked fall*/