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: wonderfl particle 2 : Cyclone

+ progressive blur
/**
 * Copyright signedvoid ( http://wonderfl.net/user/signedvoid )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eEYl
 */

// forked from gameegg's wonderfl particle 2 : Cyclone
//    + progressive blur
// forked from gameegg's wonderfl particle
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;
    import flash.utils.getTimer;

    public class WonderflParticle extends Sprite {
        
        private var space:Sprite;
        private var bit:Bitmap;
        private var bitd:BitmapData;
        private var displayBD:BitmapData;
        private var bf:BlurFilter;
        private var ctf:ColorTransform;
        private var textbox:TextField;
        private var dotVector:Vector.<Dot>;
        private var mouseDown:Boolean;
        private var downTime:int;
        
        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);
            displayBD = new BitmapData(465, 465, false, 0);
            bit = new Bitmap(displayBD);
            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();
            var blurTime:int = getTimer() - downTime;
            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;
                    var r:Number = pit(tmpdot.x,tmpdot.y,mouseX,mouseY);
                    var th:Number = Math.atan2(mouseY-tmpdot.y,mouseX-tmpdot.x);
                    if(r>25){
                    tmpdot.x += Math.cos(th+1.2)*100/r//(mouseX - tmpdot.x)/100;
                    tmpdot.y += Math.sin(th+1.2)*100/r//(mouseY - tmpdot.y)/100;
                    }
                    else {
                    tmpdot.x += Math.cos(th+1.2)*2
                    tmpdot.y += Math.sin(th+1.2)*2
                    }

                }
                else {
                    //tmpdot.sx += (tmpdot.ox - tmpdot.x)/100;
                    //tmpdot.sy += (tmpdot.oy - tmpdot.y)/100;
                    tmpdot.x += (tmpdot.ox - tmpdot.x)/5;
                    tmpdot.y += (tmpdot.oy - tmpdot.y)/5;
                }
                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);
            bf.blurX = bf.blurY = mouseDown ? blurTime * 0.003 + 1.2 : 1.2;
            displayBD.applyFilter(bitd, bitd.rect, new Point(), bf);
        }
        
        private function pit(a:Number,b:Number,c:Number,d:Number):Number{
            return Math.sqrt((a-c)*(a-c)+(b-d)*(b-d));
        }

        
        private function md(e:MouseEvent):void {
            mouseDown = true;
            downTime = getTimer();
            for(var k:int = 0; k < dotVector.length; ++k) {
                var tmpdot:Dot = dotVector[k];
                tmpdot.sx =0;
                tmpdot.sy =0;
            }
        }
        
        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
    }

}