Matches - Raphaël eye candy

Thegor - The Graphic Operation Runner

by andersand

JavaScript

/**
 * Matches - Raphaël eye candy.
 * --
 * 
 * Thegor - "The Graphic Operation Runner"
 * 
 * @author andersand // [email protected]
 */
(function() {
    var config = {
        name : "Matches",
        credits : "andersand 2011",
        width : 600,
        height : 600,
        initialWait : 1000,
        interval : 20,
        repetitions : 500,
        maxSimultaneousElements : 100,
        operationSelection : "ordered", // "random", "ordered", "reversed"
        elementRemoval : "fifo", // "random", "fifo", "lifo"
        selectedOperations : [], // named operations (none means include all)
        /**
         * an array of all operations available to Thegor. an operation is an object with a
         * name property a funk property. the name may be used in conjunction with the config
         * option 'selectedOperations' and funk needs to return a Raphaël element or an array
         * of such elements.  
         */
        operations : [
        {
            name : "match",
            funk : function(paper, i) { 
                var len = 40;
                var x1, y1, x2, y2, headingX, headingY;
                if (elementStack.length === 0) {
                    x1 = rnd2(0, config.width-len);
                    y1 = rnd2(0, config.height-len);
                    x2 = x1+len;
                    y2 = y1+len;
                    headingX = 1;
                    headingY = 1;
                }
                else {
                    var prev = elementStack[elementStack.length-2];
                    var degs = rnd(120);
                    var angle = degs * Math.PI / 180;
                    var xChange = len * Math.sin(angle),
                        yChange = len * Math.cos(angle);
                    headingX = prev.headingX;
                    headingY = prev.headingY;
                    var tryX = prev.x2 + xChange*headingX,
                        tryY = prev.y2 + yChange*headingY;
                    if (tryX >...