Disco

Based upon example "disco" in "Jumpstart Coffeescript"

by rulokc

HTML

<div id="game"></div>

CSS

#game {
    width: 300px;
    height: 150px;
    background-color: #000;
    position: relative;
}
.box {
    width: 14px;
    height: 14px;
    position: absolute;
    top: 0;
    left: 0;
}

JavaScript

function noise() {
    for (var x = 0; x < 20; x++) {
        for (var y = 0; y < 10; y++) {
            var hue = Math.floor(Math.random() * 360);
            var color = "hsl(" + hue + ", 60%, 50%)";
            var $box = $('.box-' + x + '-' + y);
            if ( !$box.length ) {
                $box = $('<div class="box box-' + x + '-' + y + '"></div>').appendTo('#game');
            }
            $box.css({'top':(y*15) + 'px', 'left': (x*15) + 'px', 'background-color': color});
        }
    }
}

setInterval(noise, 100);