Anonymous user
Brownian tree: Difference between revisions
m
→{{header|REXX}}: tided up some code.
m (→{{header|REXX}}: elided a statement.) |
m (→{{header|REXX}}: tided up some code.) |
||
Line 3,703:
mote = '·' /*character for a loose mote (of dust).*/
hole = ' ' /* " " an empty spot in field.*/
clearScr = 'CLS' /*(DOS) command to clear the screen. */▼
seedPos = 0 /*if =0, then use middle of the field.*/
/* " -1, " " a random placement.*/
/*otherwise, place the seed at seedPos.*/
/*use RANDSEED for RANDOM repeatability*/
parse arg
if
if
if
/* [↑] either a # ─or─ a # with a %.*/
if
if length(tree)==2
if datatype(randSeed,'W') then call random ,,randSeed /*if an integer, use the seed.*/
/* [↑] set the first random number. */
if
if
if sw==0
seedAt= seedPos /*assume a seed position (initial pos).*/
if seedPos== 0 then seedAt=
if seedPos==-1 then seedAt= random(1,
parse var seedAt xs ys . /*obtain the X and Y seed coördinates*/
/* [↓] if right─most ≡ '%', then use %*/
if right(motes, 1)=='%' then motes=
@.= hole /*create the Brownian field, all empty.*/
@.xs.ys=
loY= 1; hiY= height /*used to optimize the mote searching.*/▼
/*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ soooo, this is Brownian motion.*/
do
if loX
do x =minX to maxX; xm= x - 1; xp= x + 1 /*two handy─dandy values. */▼
/*──────────────────────────────────────────────────────────────────────────────────────*/▼
crop: do yc=-1 to sd+1 by sd+2; do xc=-1 to
do xc=-1 to sw+1 by sw+2; do yc=-1 to
/*──────────────────────────────────────────────────────────────────────────────────────*/▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
do y=minY to maxY; if @.x.y\==mote then iterate /*Not a mote: keep looking.*/
if x<loX then loX=x; if x>hiX then hiX=x /*faster than hiX=max(X,hiX)*/
if y<loY then loY=y; if y>hiY then hiY=y /*
if @.xm.y ==tree then do; @.x.y= tree; iterate; end /*there a neighbor of tree? */
if @.xp.y ==tree then do; @.x.y= tree; iterate; end /*
ym= y - 1
if @.x.ym ==tree then do; @.x.y= tree; iterate; end /*
if @.xm.ym==tree then do; @.x.y= tree; iterate; end /*
if @.xp.ym==tree then do; @.x.y= tree; iterate; end /*
yp = y + 1
if @.x.yp ==tree then do; @.x.y= tree; iterate; end /*
if @.xm.yp==tree then do; @.x.y= tree; iterate; end /*
if @.xp.yp==tree then do; @.x.y= tree; iterate; end /*
motion= 1 /* [↓] Brownian motion is coming. */
xb= x + random(1, 3) - 2 /* apply Brownian motion for X. */
Line 3,762 ⟶ 3,774:
@.x.y= hole /*"empty out" the old mote position. */
@.xb.yb= mote /*move the mote (or possibly not). */
if xb<loX then loX= max(1, xb); if xb>hiX then hiX= min(
if yb<loY then loY= max(1, yb); if yb>hiY then hiY= min(
end /*y*/ /* [↑] limit mote's movement to field.*/
end /*x*/; return</lang>
▲ end /*winks*/ /*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
▲exit 0 /*stick a fork in it, we're all done. */
▲/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ /* [↓] delete motes (moved off field).*/
▲ do xc=-1 to width+1; if @.xc.yc==hole then iterate; @.xc.yc= hole
▲ end /*yc*/
▲ do yc=-1 to height+1; if @.xc.yc==hole then iterate; @.xc.yc= hole
▲ end /*xc*/; return
▲/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ do ys=height for height by -1; aRow=
▲ do xs=1 for width; aRow= aRow || @.xs.ys
▲ end /*xs*/
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console).
|