Vermiculate

Raphaël eye candy based on Thegor - The Graphic Operation Runner

by andersand

JavaScript

/**
 * "Vermiculate", not as fancy as fdm im afraid :(
 * 
 * Raphaël eye candy based on Thegor
 * 
 * @author andersand // [email protected]
 */
(function() {
    var config = {
        name : "Vermiculate",
        credits : "andersand 2011\ninspired by Tyler Pierce's fdm\nhttp://www.eclipse.net/~gmcsf/fdm/",
        width : 400,
        height : 600,
        initialWait : 1000,
        interval : 20,
        repetitions : 500,
        maxSimultaneousElements : 200,
        operationSelection : "random", // "random", "ordered", "reversed"
        elementRemoval : "fifo", // "random", "fifo", "lifo"
        selectedOperations : [], // named operations (none means include all)
        /**
         * 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 : "wiggyly worm",
            funk : function(paper, i) { 
                var len = 10;
                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-1];
                    var degs = rnd(90);
                    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 > config.width || tryX < 0) {
                  ...