Updating
Updated
HTML <body>
JS <script> (jQuery supported)
');
}
function ping(){
$(".thing:nth-child("+(Math.floor(Math.random()*total)+1)+")").attr("val", 255);
}
function run(){
if (Math.random() < .2)
ping();
$(".thing").each(function (i){
var val = parseInt($(this).attr("val"));
if (val > 0){
var s = val*spred;
var prev = i-1;
if (prev < 0)
prev = total-1;
update(prev, s);
var up = i-mod;
if (up < 0)
up = total+up;
update(up, s);
var down = i+mod;
if (down > total)
down = down-total;
update(down, s);
var next = i+1;
if (next >= total)
next = 0;
update(next, s);
update(i, val*dec, true);
}
});
}
function update(index, value, full){
if (typeof full == "undefined")
full = false;
var div = $(".thing:nth-child("+(index+1)+")");
if (full)
var val = Math.floor(value);
else
var val = Math.floor(parseInt(div.attr("val")) + value);
if (!val)
val = 0;
if (val > 255)
val = 255;
div.attr("val", val);
var color = 255-val;
div.css("background-color", "rgb("+color+","+color+","+color+")");
}
setInterval(function (){ run(); }, 60);