Matrix digital rain: Difference between revisions

m
J: some minor documentation
m (J: some minor documentation)
Line 1,092:
timer 42
}}</lang>
 
Notes:
 
<tt>timer 42</tt> to roughly match the frame rate used in the matrix movie (so we update the display roughly once every 42 milliseconds).
 
Some key data structures here are a matrix (pun intended) of displayed characters named 'canvas', a corresponding matrix counting how many screen updates remain for each character named 'hp', a list of candidate unicode characters named 'junk', a matrix representing color for each 'hp' value named 'heat' (initial value is white, when hp reaches zero, the value is black, in between are shades of green).
 
Also, there's a sequence of injection points characterized by 'cols' and 'rows', which (taken together) form an index into 'canvas' and into 'hp'. Every update, we add a random value to 'cols' and a corresponding zero to 'rows'. Also, every update, we add a new random character (picked from junk) to 'canvas' (with a corresponding max value added to 'hp') at every position characterized by the rows,cols pair. Then we update the display based on the canvas and hp{heat values. (Finally, in each update, we decrement every value in heat that was above zero, and remove from cols and rows a possible pair which corresponds to the last row of the screen.)
 
Conceptually, it would be better to only track characters which would be rendered with green or white. This would allow multiple characters to be rendered at the same position (which would better match the characteristic behavior of the display tube mechanism being emulated here).
 
=={{header|Javascript}}==
6,962

edits