Unnamed - Raphaël eye candy

Thegor - The Graphic Operation Runner

by andersand

JavaScript

/**
 * Unnamed - Raphaël eye candy.
 * 
 * Graphic Operation Runner
 * 
 * @author [email protected]
 */
(function() {
    var config = {
        name : "Unnamed eye candy",
        credits : "andersand 2011",
        selectedOperations : ["line", "circle"],
        width : 700,
        height : 600,
        initialWait : 1000,
        interval : 2,
        repetitions : 5000,
        maxSimultaneousElements : 1000,
        operationSelection : "random", // "random", "selectionOrder", "reverseSelectionOrder"
        elementRemoval : "random", // "random", "fifo", "lifo"
        doneOperation : function(index, element) {
            element.animate({opacity : 0}, 1500);
        }
    };
    
    // runtime variables
    var operationIndex = 0,
        elementStack = [],
        aborted = false;
    
    // helper functions
    function rnd(max) {
        return Math.round(Math.random()*max);
    }
    function rnd2(min, max) {
        return min+rnd(max-min);
    }
    function rnd3(min, max) {
        return min+Math.random()*max;
    }
    
    /**
     * Creates the available operations
     * @return array of functions
     */
    function setupOperations(paper) {
        var operations = [];
        var opLine = {
            name : "line",
            fun : function(i) { 
                var xL = rnd2(5, 30),
                    yL = rnd2(5, 30);
                var x1 = rnd2(0, config.width),
                    y1 = rnd2(0, config.height);
                if (rnd(1)) {
                    xL *= -1;
                }
                if (rnd(1)) {
                    yL *= -1;
                }
                var x2 = (x1-xL > 0 ? x1-xL : x1+xL),
                    y2 = (y1-yL > 0 ? y1-yL : y1+yL);
                var element = paper.path(
                    "M" + x1 + " " + y1 + 
                    "L" + x2 + " " + y2
                );
                element.attr({stroke : "#fff", "stroke-width" : 2});
                return element;
  ...