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: flash on 2010-9-14

Vectorで一個ずつ処理か
それぞれにイベントリスナか
どっちが速いかっていうと明らかに前者
Get Adobe Flash player
by Thy 17 Sep 2010

    Talk

    Hasufel at 18 Sep 2010 02:46
    u should put rect in private up there instead of in the enterframe ;)
    Embed
// forked from Susisu's flash on 2010-9-14
/*
    Vectorで一個ずつ処理か
    それぞれにイベントリスナか
    どっちが速いかっていうと明らかに前者
*/
package {
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.StageQuality;
    import flash.display.Graphics;
    import flash.events.Event;
    import flash.display.Sprite;
    import net.hires.debug.Stats;
    [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="120")]
    public class FlashTest extends Sprite {
        private var 
        circle_data:BitmapData = new BitmapData(9, 9, true, 0xFFFFFF),
        data:BitmapData = new BitmapData(465,465,false,0xFFFFFF),
        bitmap:Bitmap = new Bitmap(data),
        //
        pos:Vector.<Number> = new Vector.<Number>(10000*2, true);
        public function FlashTest() {
            var 
            sprite:Sprite = new Sprite(),
            g:Graphics = sprite.graphics;
            addChild(bitmap);
            g.lineStyle(1,0,1);
            g.drawCircle(5,5,4);
            circle_data.draw(sprite);
            g.clear(); g = null; sprite = null;
            
            for(var i:int=0;i<10000;i++){
                pos[i*2] = 465 * Math.random(); // x
                pos[i*2+1] = 465 * Math.random(); // y
            }
            addChild(new Stats());
            addEventListener(Event.ENTER_FRAME,onEnterFrame);
            stage.quality = StageQuality.LOW;
        }
        public function onEnterFrame(e:Event):void{
            var rect:Rectangle = new Rectangle(0,0,465,465);
            var i:int = -1; var p:Point = new Point();
            data.lock();
            data.fillRect(rect, 0xFFFFFF);
            rect.width = rect.height = 9;
            while(++i < 20000) // 10000 * 2 (x,y)
            {
                p.x = (pos[i] += Math.random()*2-1);
                p.y = (pos[++i] += Math.random()*2-1);
                data.copyPixels(circle_data, rect, p);
            }
            data.unlock();
        }
    }
}