js1k entry

by Ron Valstar

HTML

<canvas id="c"></canvas>

JavaScript

var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218

with (a)with (Math) {
    // VARS
    a.F=fillRect;
    a.T=translate;
    var o = window
        ,h = c.height = o.innerHeight
        ,w = c.width = o.innerWidth
        // move
        ,x = t = w/2 // position and half width
        ,y = j = h/2 // position and half height
        ,u = v = r = 0    // velocity x y rotation
        // misc
        ,n = .25*PI
        ,z = '#000'
        ,q = '#800'
    // FUNCTIONS
        ,R = random
        ,I = floor
        ,G = function(l){globalCompositeOperation=l||'source-over';} // copy doesn't work in IE9 and darker not in FF
        ,L = function(l,g){fillStyle=l;g&&(globalAlpha=g)}
        ,H = function H(r) {
            beginPath();
            g = -r*.675;
            e = .71;
            arc(-e*r,g,r,-5*n,-n);
            arc(e*r,g,r,-3*n,n);
            lineTo(0,2.2*r+g);
            fill()
        };
    function N(n){return n*(R()-.5)}
    // INIT DATA
    // create heart
    F(0,0,w,h);
    T(t,j);
    L("#fff",.1);
    for (i=0,l=66,k=h/4,s=k/l/2;i<l;i++){
        if(i==22)L(z);
        H(k-i*s)
    }
    // add radial
    p = createRadialGradient(0,0, 0, 0,0, .7*h);
    p.s=p.addColorStop;
    p.s(0,"#400");p.s(.43,q);p.s(1,z);
    L(p,1);
    G('lighter');
    F(-t,-j,w,h);
    //
    // save pixeldata
    d = getImageData(0,0,w,h).data;
    //
    // FILL SCREEN
    G();
    L(q,1);
    F(-t,-j,w,h);
    L(p,.2);
    F(-t,-j,w,h);
    //
    // animate
    F = function(){
        G(R()<.5?'lighter':0);
        //
        // current slope
        k = I(x);
        s = I(y);
        m = d[4*(s*w+k)];
        //
        L('#'+I(R()*2E7).toString(16),.05+m/777); // 2E7!=16777215  ... close enough
        T(x,y);
        rotate(r+=N(9));
        H(1+m*m*h/5E6 );
        //
        // change velocity
        l = .3+m/255;
        u =...