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

forked from: Yennifer Cumpleaños

vladimir ramírez
/**
 * Copyright NewKrok ( http://wonderfl.net/user/NewKrok )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/30cK
 */

// forked from vlad.el.rojo's Yennifer Cumpleaños
// vladimir ramírez 
package {
    import flash.display.Sprite;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    public class test extends Sprite {
        public function test () :void {
            var back:BitmapData = new BitmapData(465, 465, false, 0xffffff);
            back.perlinNoise(465, 465, 9, new Date().getTime(), false, true, 7, true);
            back.colorTransform(back.rect, new ColorTransform(1, 1, 1, 1, 100, 100, 100, 0));
            var grad:Shape = new Shape();
            grad.graphics.beginGradientFill(GradientType.RADIAL, [0x00ace2, 0x000000], [1, 1], [0, 255], new Matrix(0.6, 0, 0, 0.6, 232.5, 232.5));
            grad.graphics.drawRect(0, 0, 465, 465);
            back.draw(grad, null, null, BlendMode.MULTIPLY);
            addChild(new Bitmap(back));
            for ( var i:uint = 0; i < 5; i++ ) {
                 for ( var j:uint = 0; j < 5; j++ ) {
                    var t:FlashTest = addChild ( new FlashTest ( 40 + i * 100, 40 + j * 100 ) ) as FlashTest;
                    t.scaleX = t.scaleY = .5;
                 }
            }
        }
    }
}

import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.text.*;
class FlashTest extends Sprite {
    
    private var list:Array;
    private var total:Number;
    private var shape:Sprite;
    private var samples:BitmapData;
    private var m3:Matrix3D;
    private var time:int;
    
    public function FlashTest( $x:Number, $y:Number ) {
        x = $x;
        y = $y;
        shape = new Sprite();
        
        shape.graphics.lineStyle(12, 0x000000);
        shape.graphics.drawCircle(0, 0, 64);
        shape.graphics.lineStyle();
        list = [];
        total = 0;
        for (var i:int = 0; i < 5; i++) {
            var t:Number = Math.PI / 25 * (i * i + i);
            var e:Number = i + 2;
            var r:Number = 70 - e;
            var p:Particle = new Particle();
            p.place(e, t, r * Math.sin(t), -r * Math.cos(t));
            p.bend(0.97, 1, -0.19 * Math.random() - 0.01);
            list.push(p);
            total += e;
        }
        addEventListener(Event.ENTER_FRAME, grow);
        
        shape.filters = [new DropShadowFilter ( 2, 45, 0xFFFFFF, 1, 0, 0, 1, 1, true )];
        samples = new BitmapData(512, 1, false, 0x808080);
        samples.perlinNoise(60, 2, 3, new Date().getTime(), true, true, BitmapDataChannel.GREEN | BitmapDataChannel.BLUE);
        time = 0;
        shape.transform.matrix3D = m3 = new Matrix3D();
        addChild(shape);
    }
    
    private function grow(e:Event):void {
        var prob:Number = 0.5 * (1 - total / 20);
        total *= 0.97;
        for (var i:int = 0; i < list.length; i++) {
            var p:Particle = list[i];
            var x1:Number = p.x + p.b;
            var y1:Number = p.y - p.a;
            var x2:Number = p.x - p.b;
            var y2:Number = p.y + p.a;
            p.advance();
            var x3:Number = p.x - p.b;
            var y3:Number = p.y + p.a;
            var x4:Number = p.x + p.b;
            var y4:Number = p.y - p.a;
            shape.graphics.beginFill(0x000000);
            shape.graphics.moveTo(x1, y1);
            shape.graphics.lineTo(x2, y2);
            shape.graphics.lineTo(x3, y3);
            shape.graphics.lineTo(x4, y4);
            shape.graphics.endFill();
            shape.graphics.beginFill(0x000000);
            shape.graphics.moveTo(-x1, -y1);
            shape.graphics.lineTo(-x2, -y2);
            shape.graphics.lineTo(-x3, -y3);
            shape.graphics.lineTo(-x4, -y4);
            shape.graphics.endFill();
            
            if (Math.random() < prob) {
                list.push(p.fork());
                total += p.e * 0.8;
            }
            
            if (p.e < 0.4) {
                if (list.length == 1) {
                    removeEventListener(Event.ENTER_FRAME, grow);
                    return;
                } else {
                    list.splice(i--, 1);
                }
            }
        }
    }
}

internal class Particle {
    
    public var a:Number;
    public var b:Number;
    public var x:Number;
    public var y:Number;
    public var da:Number;
    public var db:Number;
    public var dx:Number;
    public var dy:Number;
    
    public function get e():Number {
        return Math.sqrt(a * a + b * b);
    }
    
    public function place(v:Number, r:Number, x:Number, y:Number):void {
        this.a = v * Math.cos(r);
        this.b = v * Math.sin(r);
        this.x = x;
        this.y = y;
    }
    
    public function bend(s:Number, t:Number, r:Number):void {
        var sin:Number = Math.sin(r);
        var cos:Number = Math.cos(r);
        da = s * cos;
        db = s * sin;
        dx = t * cos;
        dy = t * sin;
    }
    
    public function advance():void {
        var na:Number = a * da - b * db;
        var nb:Number = b * da + a * db;
        a = na;
        b = nb;
        x += a * dx - b * dy;
        y += b * dx + a * dy;
    }
    
    public function fork():Particle {
        var p:Particle = new Particle();
        p.a = a * 0.8; p.b = b * 0.8; p.x = x; p.y = y;
        p.bend(0.95, 1, (Math.random() - 0.5) * 0.4);
        return p;
    }
    
}