The JSL uses a data table to keep a row of data per moving point in the video.
The ForEachRow loops use the column name variables rowpos and colpos to place a point at a row,column in the bitmap matrices and rowstep and colstep to advance the rowpos and colpos for each frame.
dt = New Table( "points", "private", // private is *much* faster
Add Rows( npoints ), // this table has a row per moving point, location, vector, color
New Column( "rowpos" ), New Column( "colpos" ), New Column( "rowstep" ), New Column( "colstep" ),
New Column( "bounce" ), New Column( "rpix" ), New Column( "gpix" ), New Column( "bpix" )
);
Advancing the points for the next frame:
movepoints = Function( {}, // on each frame the points are all advanced and checked for leaving the bitmap
For Each Row( dt,
If( 1 <= (dt:rowpos + dt:rowstep) < nr + 1, // hit bottom or top edge?
0 // not leaving
, // else...hit the edge
dt:bounce += 1;
If( dt:bounce > bounceLimit,
reset( Row() ) // restart
, // else keep bouncing
dt:rowstep = -dt:rowstep // if bouncing, reverse
);
);
If( 1 <= (dt:colpos + dt:colstep) < nc + 1, // hit left or right edge?
0 // not leaving
, // else...hit the edge
dt:bounce += 1;
If( dt:bounce > bounceLimit,
reset( Row() ) // restart
, // else keep bouncing
dt:colstep = -dt:colstep // reverse
);
);
dt:rowpos += dt:rowstep; // move this point along its path
dt:colpos += dt:colstep;
)
);
The complicated if statements are testing if the point is about to leave the frame; an early version used bounceLimit=1 to let them bounce once by reversing the step.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.