Galton box animation: Difference between revisions

→‎{{header|REXX}}: added boilerplate code to know that the program's name is, and also to know which program to use to clear the terminal screen.
m (→‎{{header|REXX}}: refreshed the output.)
(→‎{{header|REXX}}: added boilerplate code to know that the program's name is, and also to know which program to use to clear the terminal screen.)
Line 2,873:
hard-coded to   '''CLS'''.
<lang rexx>/*REXX pgm simulates Sir Francis Galton's box, aka: Galton Board, quincunx, bean machine*/
if !all(arg()) then exit /*Any documentation was wanted? Done.*/
if !cms then address '' /*handle ADDRESS for CMS oper. system. */
trace off /*suppress error messages from a HALT. */
signal on halt /*allow the user to halt the program.*/
parse arg rows balls freezfreeze seed . /*obtain optional arguments from the CL*/
if rows =='' | rows=="," then rows= 0 /*Not specified? Then use the default.*/
if balls=='' | balls=="," then balls= 100 /* " " " " " " */
if freezfreeze=='' | freezfreeze=="," then freezfreeze= 0 /* " " " " " " */
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. */
Line 2,886 ⟶ 2,888:
sw= sw - 1; if sw//2 then sw= sw -1 /* " " " odd " width.*/
if rows==0 then rows= (sw - 2 ) % 3 /*pins are on the first third of screen*/
clearScreen= 'CLS' /*the (OS) command to clear the screen.*/
pin = '·'; ball = '☼' /*define chars for a pin and a ball.*/
call gen /*gen a triangle of pins with some rows*/
Line 2,900 ⟶ 2,901:
run: do step=1; call drop; call show; end /*step*/ /*'til run out of balls.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
halt: say '***warning*** REXX program' "GALTON" !fn "execution halted by user.'"; exit 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
drop: static= 1 /*used to indicate all balls are static*/
Line 2,929 ⟶ 2,930:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: clearScreen!cls; info= right(" step" step, sw%4) /*title for screen.*/
do g=sd by -1 until @.g\='' /*G: last data row.*/
end /*g*/ /* [↓] show a row.*/
do r=1 for g; _= strip(@.r, 'T'); if r==2 then _= _ left('', 9) info; say _
end /*r*/; if step==freezfreeze then pulldo; say return'press ENTER ···'; pull; /* [↑] show a row.*/</lang>end
return
/*════════════════════════════════════════════════════════════════──────════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/
!all: !!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=; return !call
!env: !env='ENVIRONMENT'; if !sys=='MSDOS' | !brexx | !r4 | !roo then !env= 'SYSTEM'; if !os2 then !env= 'OS2'!env; !ebcdic= 3=='f3'x; if !crx then !env= 'DOS'; return
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .; call !sys; if !dos then do; _= lastpos('\', !fn); !fm= left(!fn, _); !fn= substr(!fn, _+1); parse var !fn !fn '.' !ft; end; return word(0 !fn !ft !fm, 1 + ('0'arg(1) ) )
!rex: parse upper version !ver !vernum !verdate .; !brexx= 'BY'==!vernum; !kexx= 'KEXX'==!ver; !pcrexx= 'REXX/PERSONAL'==!ver | 'REXX/PC'==!ver; !r4= 'REXX-R4'==!ver; !regina= 'REXX-REGINA'==left(!ver, 11); !roo= 'REXX-ROO'==!ver; call !env; return
!sys: !cms= !sys=='CMS'; !os2= !sys=='OS2'; !tso= !sys=='TSO' | !sys=='MVS'; !vse= !sys=='VSE'; !dos= pos('DOS', !sys)\==0 | pos('WIN', !sys)\==0 | !sys=='CMD'; !crx= left(!sys, 6)=='DOSCRX'; call !rex; return
!var: call !fid; if !kexx then return space( dosenv( arg(1) ) ); return space( value( arg(1), , !env) )</lang>
This REXX program makes use of &nbsp; '''SCRSIZE''' &nbsp; REXX program (or
BIF) which is used to determine the screen