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-7-20

Get Adobe Flash player
by yama3 20 Jul 2011
    Embed
/**
 * Copyright yama3 ( http://wonderfl.net/user/yama3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kSBJ
 */

package {
    import net.hires.debug.Stats;
    
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.geom.ColorTransform;
    
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    import flash.filters.BlurFilter;
    import frocessing.color.ColorHSV;
    
    [SWF(width='465', height='465', backgroundColor='0x000000', frameRate='25')]
    
    public class FlashTest extends Sprite {
        private var p_vec:Vector.<PARTICLE> = new Vector.<PARTICLE>();
        private var color:ColorHSV = new ColorHSV(20);
        private var pixel:BitmapData;
        private var stats:Stats;
        
        private var ct_01:ColorTransform;
        private var bf_01:BlurFilter;
        private var mt_01:Matrix;
        
        private var h:uint;
        private var w:uint;
        
        public function FlashTest() {
            stage ? init():addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init():void
        {
            if(hasEventListener(Event.ADDED_TO_STAGE))
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
            }
            
            h = stage.stageHeight;
            w = stage.stageWidth;
            
            stage.scaleMode = 'noScale';
            
            graphics.beginFill(0, 1);
            graphics.drawRect(0, 0, w, h);
            
            bf_01 = new BlurFilter(1, 1);
            mt_01 = new Matrix
            (
                2, 0, 0, 2, -w / 2, 0
            );
            
            ct_01 = new ColorTransform
            (
                1, 1, 1, 0.35
            );
            
            pixel = new BitmapData
            (
                w, h, false, 0
            );
            
            addChild(new Bitmap(pixel));
            
            stats = new Stats();
            stats.visible = false;
            
            addChild(stats);
            
            stage.addEventListener(MouseEvent.CLICK, onClick);
            stage.addEventListener(Event.ENTER_FRAME, update);
        }
        
        private function onClick(e:MouseEvent):void
        {
            stats.visible = ! stats.visible;
        }
        
        private function update(e:Event):void
        {
            render();
            
            for each(var p:PARTICLE in p_vec)
            {
                p.x += p.vx;
                p.y += p.vy;
                p.vx *= 1.02;
                p.vy *= p.y / h;
                
                pixel.setPixel32(p.x, p.y, p.c);
                
                if(p.y < 0 || h < p.y || p.x < 0 || p.x > w)
                {
                    p_vec.splice(p_vec.indexOf(p), 1);
                }                
            }
            
            var p_num:uint = 15 + Math.random() * 50;
            
            for(var i:uint = 0; i < p_num; i++)
            {
                var n:PARTICLE = new PARTICLE();
                
                n.c = color.value32;
                n.x = w / 2;
                n.y = Math.random() * h;
                n.vx = 5 * (Math.random() - 0.5);
                n.vy = 5 * (Math.random() - 0.5);
                
                p_vec.push(n);
            }
            color.h = 15 + Math.random()*25;
        }
        
        private function render():void
        {
            pixel.lock();
            
            pixel.colorTransform(pixel.rect, ct_01);
            pixel.draw(pixel, mt_01, null, 'add', null, true);
            pixel.applyFilter(pixel, pixel.rect, new Point(0,0), bf_01);
            
            pixel.unlock();
        }
    }
}

class PARTICLE
{
    public var c:uint;
    public var x:Number;
    public var y:Number;
    public var vx:Number;
    public var vy:Number;
}