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

[朝ワン]以前作った「test」を少しずつ高速に

朝ワンのネタがないからちょっとずつ高速化を目指す。
* まず、bitmapData を lock した。
* 2回目にして設計を別モノに変えた。
* 元これ
* http://wonderfl.net/code/7744487e2f3d3385ce38b2f63966e602b893fd8c
// forked from bkzen's forked from: test[朝わん]
// forked from bkzen's test
/**
 * 朝ワンのネタがないからちょっとずつ高速化を目指す。
 * まず、bitmapData を lock した。
 * 2回目にして設計を別モノに変えた。
 * 元これ
 * http://wonderfl.net/code/7744487e2f3d3385ce38b2f63966e602b893fd8c
 */
// write as3 code here..
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import net.hires.debug.Stats;
	
    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
    public class Asawon4 extends Sprite
    {
        private var color: uint = 0xFFFFFF;
        private const num: int = 500;
        private var bf: BlurFilter = new BlurFilter(2, 2);
        private var particle:Particle;
        private var bmd:BitmapData;
        private var bmp:Bitmap;
        private var canvas:Shape;
        private var point:Point = new Point();
        private var ox: Number = 232;
        private var oy: Number = 232;
        
        public function Asawon4() 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e: Event = null): void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            //
            bmd = new BitmapData(465, 465, false, 0x0);
            bmp = new Bitmap(bmd);
            addChild(bmp);
            
            var prev: Particle = particle = new Particle(0, color);
            var p: Particle, i: int;
            while (++i <= num)
            {
                p = new Particle(i * Math.PI / 180, color);
                prev.next = p;
                prev = p;
            }
            canvas = new Shape();
            addEventListener(Event.ENTER_FRAME, draw);
            stage.addEventListener(MouseEvent.CLICK, onClick);
            addChild(new Stats());
        }
        
        private function draw(e:Event):void 
        {
            var p: Particle = particle, g: Graphics = canvas.graphics, bx: Number, by: Number;
            bmd.lock();
            g.clear();
            while ((p = p.next) != null)
            {
                bx = p.x;
                by = p.y;
                p.x += p.vx;
                p.y += p.vy;
                p.vx += (Math.random() * 100 - Math.random() * 100) * 0.005;
                p.vy += (Math.random() * 100 - Math.random() * 100) * 0.005;
                g.lineStyle(1, p.color, 0.3);
                g.moveTo(ox + bx, oy + by);
                g.lineTo(ox + p.x, oy + p.y);
                g.moveTo(ox - bx, oy + by);
                g.lineTo(ox - p.x, oy + p.y);
                g.moveTo(ox + bx, oy - by);
                g.lineTo(ox + p.x, oy - p.y);
                g.moveTo(ox - bx, oy - by);
                g.lineTo(ox - p.x, oy - p.y);
                if (p.age++ > 200) p.reset(color);
            }
            bmd.draw(canvas);
            bmd.applyFilter(bmd, bmd.rect, point, bf);
            bmd.unlock();
            color = (Math.random() * 10000 > 9950) ? randomColor() : color;
        }
        
        
        private function onClick(e:MouseEvent):void 
        {
            color = randomColor();
        }
        
        private function randomColor(): uint
        {
            var r: int = Math.random() * 128 + 128;
            var g: int = Math.random() * 128 + 128;
            var b: int = Math.random() * 128 + 128;
            return (r << 16) | (g << 8) | b;
        }
    }
    
}
class Particle
{
    public var x:  Number;
    public var y:  Number;
    public var vx: Number;
    public var vy: Number;
    public var age: int;
    public var next: Particle;
    public var color: uint;
    
    function Particle(r: Number, color: uint)
    {
        vx = 2 * Math.cos(r);
        vy = 2 * Math.sin(r);
        x = 30 * Math.sin(r);
        y = 30 * Math.cos(r);
        age = Math.random() * 200;
        this.color = color;
    }
    
    public function reset(color: uint): void
    {
        var r: Number = Math.random() * Math.PI * 2;
        x = 30 * Math.sin(r);
        y = 30 * Math.cos(r);
        vx = vy = age = 0;
        this.color = color;
    }
}