Laser Symmetry - Raphaël eye candy

Thegor - The Graphic Operation Runner

by andersand

HTML

<div id="gfx"></div>

JavaScript

/**
 * Laser Symmetry - Raphaël eye candy.
 *
 * [ Testing some event handling here as well ]
 *
 * Somewhat configurable Graphic Operation Runner (GOR)
 *
 * TBD: [configurability] features only random operation selection, make configurable 
 * TBD: [configurability] features only random element removal, make configurable 
 *
 * @author [email protected]
 */
var andersand = {
    config : {
        name : "Laser Symmetry",
        credits : "andersand 2011",
        selection : ["twin lasers"],
        width : 600,
        height : 600,
        initialWait : 2000,
        interval : 20,
        repetitions : 500,
        maxSimultaneousElements : 100,
        doneOperation : function(index, element) {}
    },
    elementStack : [],
    rnd : function(max) {
        return Math.round(Math.random()*max);
    },
    rnd2 : function(min, max) {
        return min+andersand.rnd(max-min);
    },
    rnd3 : function(min, max) {
        return min+Math.random()*max;
    },
    operations : function(paper) {
        var operations = [];
        var config = andersand.config;
        var rnd = andersand.rnd,
            rnd2 = andersand.rnd2;

        operations.push({
            name : "twin lasers",
            fun : function(i) { 
                var x = i%2 ? 0 : config.width;
                var element = paper.path(
                    "M" + x + " " + (config.height/2) + 
                    "L" + (config.width/2) + " " + rnd(config.height)
                );
                var rndColor = "rgb(_,_,_)".replace(/_/g, function() {return rnd2(64,192);});
                element.attr({stroke : rndColor, "stroke-width" : 2});
                andersand.elementStack.push(element);
            }
        });
        
        // intersect available operations with selected operations
        return (function () {
            var ops = [];
            var all = false;
            if (!config.selection || config.selection.length === 0) {
                all =...