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

wonderfl particle

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

package {
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.text.TextField;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Sprite;
    public class WonderflParticle extends Sprite {
        
        private var space:Sprite;
        private var bit:Bitmap;
        private var bitd:BitmapData;
        private var bf:BlurFilter;
        private var ctf:ColorTransform;
        private var textbox:TextField;
        private var dotVector:Vector.<Dot>;
        private var mouseDown:Boolean;
        
        public function WonderflParticle() {
            graphics.beginFill(0x0);
            graphics.drawRect(0,0,465,465);
            
            space = new Sprite();
            //addChild(space);
            
            textbox = new TextField();
            textbox.x = 110;
            textbox.y = 465/2 - textbox.height/2;
            
            textbox.scaleX = 5;
            textbox.scaleY = 5;
            
            bitd = new BitmapData(465,465,false,0x000000);
            bit = new Bitmap(bitd);
            addChild(bit);
            
            textbox.textColor = 0xffffff;
            textbox.text = "wonder"
            bitd.draw(textbox,textbox.transform.matrix);
            textbox.x = 290;
            textbox.textColor = 0xaa0000;
            textbox.text = "fl"
            bitd.draw(textbox,textbox.transform.matrix);
            
            
            bf = new BlurFilter(16,16,3);
            ctf = new ColorTransform(1,1,1,0.5);
            mouseDown = false;
            
            dotVector = new Vector.<Dot>();
            
            for(var i:int = 0; i<465; ++i) {
                for(var j:int = 0; j<465; ++j) {
                    var color:Number = bitd.getPixel(j,i);
                    if(color != 0x0){
                        var dot:Dot = new Dot(j,i,j,i,color);
                        dotVector.push(dot);
                    }

                }

            }
            
            
            stage.addEventListener("mouseDown",md);
            stage.addEventListener("mouseUp",mu);
            addEventListener("enterFrame",ef);
            

        }
        
        private function ef(e:Event):void {
            
            //space.graphics.clear();
            bitd.colorTransform(bitd.rect,ctf);
            for(var k:int = 0; k < dotVector.length; ++k) {
                var tmpdot:Dot = dotVector[k];
                if(mouseDown){
                    //tmpdot.x += (mouseX - tmpdot.x)/10;
                    //tmpdot.y += (mouseY - tmpdot.y)/10;
                    tmpdot.sx += (mouseX - tmpdot.x)/100;
                    tmpdot.sy += (mouseY - tmpdot.y)/100;
                }
                else {
                    tmpdot.sx += (tmpdot.ox - tmpdot.x)/100;
                    tmpdot.sy += (tmpdot.oy - tmpdot.y)/100;
                    tmpdot.x += (tmpdot.ox - tmpdot.x)/50;
                    tmpdot.y += (tmpdot.oy - tmpdot.y)/50;
                }
                tmpdot.update();
                //space.graphics.beginFill(tmpdot.color);
                //space.graphics.drawCircle(tmpdot.x,tmpdot.y,1);
                bitd.setPixel(tmpdot.x,tmpdot.y,tmpdot.color);
            }
            
            //graphics.clear();
            //bitd.draw(space,space.transform.matrix);
            
        }
        
        private function md(e:MouseEvent):void {
            mouseDown = true;
            
            for(var l:int = 0; l < dotVector.length; ++l) {
                var tmpdot:Dot = dotVector[l];
                var rotation:Number = Math.random()*Math.PI*2;
                
                tmpdot.sx += Math.cos(rotation)*Math.random()*50;
                tmpdot.sy -= Math.sin(rotation)*Math.random()*50;
            }
        }
        
        private function mu(e:MouseEvent):void {
            mouseDown = false;
        }


    }
}

internal class Dot {
    public var px:Number = 0;
    public var py:Number = 0;
    public var x:Number = 0;
    public var y:Number = 0;
    public var ox:Number = 0;
    public var oy:Number = 0;
    public var sx:Number = 0;
    public var sy:Number = 0;
    public var color:Number = 0;
    
    public function Dot(ix:Number,iy:Number,iox:Number,ioy:Number,icolor:Number) {
        px = x = ix;
        py = y = iy;
        ox = iox;
        oy = ioy;
        color = icolor;
    }
    
    public function update():void {
        px = x;
        py = y;
        x += sx;
        y += sy;
        
        sx *= 0.95
        sy *= 0.95
    }

}