In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2011-9-1

Get Adobe Flash player
by yonatan 01 Sep 2011
    Embed
/**
 * Copyright yonatan ( http://wonderfl.net/user/yonatan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/gjnvO
 */

package {
    import flash.display.Sprite;
    import flash.geom.*;

    [SWF(backgroundColor="0x808080")]
    public class main extends Sprite {
        public function main() {
            x = stage.stageWidth/2;
            y = stage.stageHeight/2;
            addEventListener("enterFrame", frame);
        }

        private var n:Number = 0;
        public function frame(e:*):void {
            var i:int, j:int;
            var tt:Turtle = new Turtle;
            tt.fd(1000).pitch(-240+(Math.sin(n/3)*50)).yaw(n*22);

            function arm(parts:int, angle:Number):void {
                tt.setColor(0x40,0x10,0,0.75);
                while(parts--) tt.p().fd(100).pitch(angle).roll(Math.sin(n)*5).scale(0.9).v(0.1).s(-0.1).a(0.02);
            }

            for(i=0;i++<12;) {
                tt.push().fd(150);
                arm(25, 23);
                tt.pop().yaw(360/12);
            }

            tt.render(graphics, 200);
            n+=0.1;
        }
    }
}

import flash.display.*;
import flash.geom.*;
import frocessing.color.*;

class Turtle {
    private var _stack:Array = []; // state stack
    private var _particles:Array = [];
    public var matrix:Matrix3D = new Matrix3D;
    public var color:FColor = new FColor;
    public var pSize:Number = 100;
    public function clear():Turtle { _stack.length = _particles.length = 0; return setColor().id(); }
    public function push():Turtle { _stack.push({m: matrix.clone(), c:color.clone(), s:pSize}); return this; }
    public function pop():Turtle { 
        if(!_stack.length) throw(new Error("Can't pop empty stack."));
        var state:Object = _stack.pop();
        matrix = state.m;
        color = state.c;
        pSize = state.s;
        return this;
    }
    public function id():Turtle { matrix.identity(); return this; }
    public function fd(n:Number):Turtle        { matrix.prependTranslation(0, 0, n); return this; }
    public function pitch(angle:Number):Turtle { matrix.prependRotation(angle, Vector3D.X_AXIS); return this; }
    public function yaw(angle:Number):Turtle   { matrix.prependRotation(angle, Vector3D.Y_AXIS); return this; }
    public function roll(angle:Number):Turtle  { matrix.prependRotation(angle, Vector3D.Z_AXIS); return this; }
    public function h(n:Number):Turtle { color.h+=n; return this; }
    public function s(n:Number):Turtle { color.s+=n; return this; }
    public function v(n:Number):Turtle { color.v+=n; return this; }
    public function a(n:Number):Turtle { color.a+=n; return this; }
    public function setColor(...args):Turtle { color.color.apply(color, args); return this; }
    public function scale(x:Number, y:Number = NaN, z:Number = NaN):Turtle {
        if(isNaN(y) && isNaN(z)) y=z=x;
        matrix.prependScale(x, y, z);
        pSize *= (x+y+z)/3;
        return this;
    }

    public function p():Turtle {
        var p:Particle = new Particle;
        p.x = matrix.position.x;
        p.y = matrix.position.y;
        p.z = matrix.position.z;
        p.rgb = color.value;
        p.a = color.a;
        p.size = pSize;
        _particles.push(p);
        return this;
    }

    public function render(g:Graphics, focus:Number):void {
        var p:Particle;
        var z:Number;
        _particles.sortOn("z", Array.NUMERIC | Array.DESCENDING);
        g.clear();
        for each(p in _particles) {
            var scale:Number = focus/(focus+p.z);
            var radius:Number = p.size*scale;
            var x:Number = p.x
            g.beginFill(p.rgb, p.a);
            g.drawCircle(p.x*scale, p.y*scale, p.size*scale);
            g.endFill();
        }
    }
}

class Particle {
    public var x:Number;
    public var y:Number;
    public var z:Number;
    public var rgb:uint;
    public var a:Number;
    public var size:Number;
}