Galton box animation: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: implemented a better method to abvoid collisions.)
(→‎{{header|REXX}}: added code to automatically freeze the REXX program to enable to capture a point in time (for a screenshot); also changed wording in the REXX section header.)
Line 2,867: Line 2,867:


Balls are dropped continuously   (up to a number specified or the default),   the default is enough rows of
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.
<br>pins to fill the top &nbsp; <big><sup>1</sup>/<sub>3</sub></big> &nbsp; rows of the terminal screen.

Extra code could've been added to check for which OS (operating system) is being used and which REXX is
<br>running to determine which program to clear the terminal (screen). &nbsp; Currently, it is
hard-coded to &nbsp; '''CLS'''.
<lang rexx>/*REXX pgm simulates Sir Francis Galton's box, aka: Galton Board, quincunx, bean machine*/
<lang rexx>/*REXX pgm simulates Sir Francis Galton's box, aka: Galton Board, quincunx, bean machine*/
trace off /*suppress error messages from a HALT. */
trace off /*suppress error messages from a HALT. */
signal on halt /*allow the user to halt the program.*/
signal on halt /*allow the user to halt the program.*/
parse arg rows balls seed . /*obtain optional arguments from the CL*/
parse arg rows balls freez seed . /*obtain optional arguments from the CL*/
if rows =='' | rows=="," then rows= 0 /*Not specified? Then use the default.*/
if rows =='' | rows=="," then rows= 0 /*Not specified? Then use the default.*/
if balls=='' | balls=="," then balls= 100 /* " " " " " " */
if balls=='' | balls=="," then balls= 100 /* " " " " " " */
if freez=='' | freez=="," then freez= 0 /* " " " " " " */
if datatype(seed, 'W') then call random ,,seed /*Was a seed specified? Then use seed.*/
if datatype(seed, 'W') then call random ,,seed /*Was a seed specified? Then use seed.*/
parse value scrsize() with sd sw . /*obtain the terminal depth and width. */
parse value scrsize() with sd sw . /*obtain the terminal depth and width. */
Line 2,928: Line 2,933:
end /*g*/
end /*g*/
do r=1 for g; _= strip(@.r, 'T'); if r==2 then _= _ left('', 9) info; say _
do r=1 for g; _= strip(@.r, 'T'); if r==2 then _= _ left('', 9) info; say _
end /*r*/; return /* [↑] show a row.*/</lang>
end /*r*/; if step==freez then pull; return /* [↑] show a row.*/</lang>
This REXX program makes use of &nbsp; '''SCRSIZE''' &nbsp; REXX program (or
This REXX program makes use of &nbsp; '''SCRSIZE''' &nbsp; REXX program (or
BIF) which is used to determine the screen
BIF) which is used to determine the screen
Line 2,939: Line 2,944:
The terminal size used for this display was &nbsp; '''64'''<small>x</small>'''96'''.
The terminal size used for this display was &nbsp; '''64'''<small>x</small>'''96'''.


{{out|output|text=&nbsp; when using the default inputs &nbsp; and the program was paused at step '''76''' to show this screen shot:}}
{{out|output|text=&nbsp; when the REXX program was "stopped" by using the inputs of &nbsp; &nbsp; <tt> , , 100 </tt> &nbsp; so as to freeze the program to capture a screenshot:}}
<pre>
<pre>

☼· step 75
·☼ step 100

·☼·
·☼·

·☼· ·
· ·☼·

· ·☼· ·
·☼· · ·

· · ·☼· ·
· · ·☼· ·

· ·☼· · · ·
· · ·☼· · ·

· · · · ·☼· ·
· · · · ·☼· ·

· · ·☼· · · · ·
· · · ·☼· · · ·

· ·☼· · · · · · ·
· · · · ·☼· · · ·

· · · · ·☼· · · · ·
· · · · ·☼· · · · ·

· · · ·☼· · · · · · ·
· · · · · · · · ·☼· ·

· · · · ·☼· · · · · · ·
· · · · ·☼· · · · · · ·

· · · · · ·☼· · · · · · ·
· · · · · · ·☼· · · · · ·

· · · · · ·☼· · · · · · · ·
· · · · · ·☼· · · · · · · ·

· · · · · · · · ·☼· · · · · ·
· · · · · · · ·☼· · · · · · ·













☼ ☼
☼ ☼
☼ ☼
☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼
</pre>
</pre>
{{out|output|text=&nbsp; when using the default inputs; &nbsp; this is the final screenshot:}}
{{out|output|text=&nbsp; when using the default inputs; &nbsp; this is the final screenshot:}}
<pre>
<pre>
· step 353

· step 148


· ·
· ·
Line 3,036: Line 3,040:
· · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · ·





☼ ☼

☼ ☼

☼ ☼

☼ ☼

☼ ☼

☼ ☼ ☼

☼ ☼ ☼ ☼

☼ ☼
☼ ☼ ☼ ☼
☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
Line 3,057: Line 3,058:
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼
</pre>
</pre>