/*
Note: something|0 -> OR and type conversion
R = Math.random()*9|0
random number between 0 and 8
R > 10 | 0
if R > 10 then 1, otherwise 0
*/
/*
used to hold the rain drop numbers before they show
like so [0,5,0,2,1,0,3,7,8]
which then produces the rain
*/
a=[];
/* rain array that will look something like this
[
'\n', '', '', '', '', '', '', '', '', // first row
'\n', '$', ' ', '$', ' ', '$', ' ', ' ', ' ',
'\n', '$', ' ', '$', ' ', ' ', ' ', '$', ' ',
'\n', ' ', '$', '$', ' ', ' ', ' ', ' ', ' ',
'\n', ' ', '$', '$', ' ', ' ', '$', ' ', '$',
'\n', ' ', '$', ' ', ' ', ' ', '$', ' ', ' ',
'\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '$',
'\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '$',
]
First row is not used so that the newline character ("\n")
is always copied into the next line.
*/
M=["\n"]; // first item is newline that gets copied to the next ones
r=0; // first random number is set to zero
setInterval('
a[r] = // set random amount of raindrops to random position
r = Math.random()*9|0;
for(i=82; // start from the bottom
i--; // progress upwards
// to each position, set the value from the upper row (if any)
// or set dollar or blank character for the number of raindrops
// from the randrop array and decrease the number of raindrops
M[i+9] = M[i] || " $"[a[i%9]-->3|0]
);
// set the document html to <pre> and rain array that gets converted
// to string using implicit JS conversion
document.body.innerHTML="<pre>"+M
',99)