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: Liquid110000 By Vector

Vector型使ったら早くなるかの検証
趣旨と違うことやってすみません
11万個パーティクル
Debugプレイヤーを使うと少し遅くなるかも
Get Adobe Flash player
by hacker_3nfulilg 21 Apr 2009
    Embed
// forked from clockmaker's Liquid110000 By Vector
// forked from munegon's forked from: forked from: forked from: forked from: Liquid10000
// forked from Saqoosha's forked from: forked from: forked from: Liquid10000
// forked from nutsu's forked from: forked from: Liquid10000
// forked from nutsu's forked from: Liquid10000
// forked from zin0086's Liquid10000
package {
    /**
    * Vector型使ったら早くなるかの検証
    * 趣旨と違うことやってすみません
    * 11万個パーティクル
    * Debugプレイヤーを使うと少し遅くなるかも
    */    
    import flash.display.*;
    import flash.geom.*;
    import flash.events.*;
    import flash.utils.*;
    import flash.geom.*;
    import net.hires.debug.Stats;
    
    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")];
    public class Liquid extends Sprite {
        private const nums:uint = 110000;
        private var bmpDat:BitmapData;
        private var vectorDat:BitmapData;
        private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
        private var bmp:Bitmap;
        private var vectorList:Vector.<VectorDat>;
        private var rect:Rectangle;
        private var cTra:ColorTransform;
        private var vR:Number;
        private var vG:Number;
        private var timer:Timer;

        public function Liquid() {
            initialize();
        }
        private function initialize():void {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.frameRate = 30;
            stage.quality = StageQuality.LOW;
            bmpDat= new BitmapData( 465, 465, false, 0x000000 );
            vectorDat= new BitmapData( 28, 28, false, 0x000000 );
            randomSeed= Math.floor( Math.random() * 0xFFFF );
            vectorDat.perlinNoise( 14, 14, 3, randomSeed, false, true, 1|2|0|0 );
            bmp= new Bitmap( bmpDat );
            addChild( bmp );

            rect = new Rectangle( 0, 0, 465, 465 )
            cTra = new ColorTransform( .8, .8, .9, 1.0 );
            vR = 0;
            vG = 0;

            vectorList = new Vector.<VectorDat>(nums, true);
            for (var i:uint = 0; i < nums; i++) {
                var px:Number = Math.random()*465;
                var py:Number = Math.random()*465;
                vectorList[i] = new VectorDat(px,py);
            }
            addEventListener( Event.ENTER_FRAME, loop );
            timer = new Timer(500, 0);
            timer.addEventListener(TimerEvent.TIMER, resetFunc);
            timer.start();
            
            addChild(new Stats);
        }
        private function loop( e:Event ):void {
            bmpDat.lock();
            bmpDat.colorTransform( rect, cTra );
            var len:uint = vectorList.length;
            var col:Number
            for (var i:uint = 0; i < len; i++) {
                var dots:VectorDat = vectorList[i];
                // ここ上手くやれば高速化できそう
                col = vectorDat.getPixel( dots.px>>4,  dots.py>>4);
                dots.ax += ( (col >> 16 & 0xff)-128 ) * .0005;
                dots.ay += ( (col >> 8  & 0xff)-128 ) * .0005;
                dots.vx += dots.ax;
                dots.vy += dots.ay;
                dots.px += dots.vx;
                dots.py += dots.vy;

                var _posX:Number = dots.px;
                var _posY:Number = dots.py;
                    
                dots.ax *= .96;
                dots.ay *= .96;
                dots.vx *= .92;
                dots.vy *= .92;
                ( _posX > 465 )?dots.px = 0:
                ( _posX < 0 )?dots.px = 465:0;
                ( _posY > 465 )?dots.py = 0:
                ( _posY < 0 )?dots.py = 465:0;

                bmpDat.setPixel( dots.px, dots.py, 0xffffff );
            }
            bmpDat.unlock();
        }
        private var seed:Number = Math.floor( Math.random() * 0xFFFF );
        private var offset:Array = [new Point(), new Point()];
        private function resetFunc(e:Event):void{
            vectorDat.perlinNoise( 14, 14, 3, seed, false, true, 1|2|0|0, false, offset );
            offset[0].x += 1.5;
            offset[1].y += 1.0;
            
            var dots:VectorDat = vectorList[0];
            vR += .001 * (dots.px-232)/465;
            vG += .001 * (dots.py-232)/465;
            ( vR > .01 ) ? vR = .01:
            ( vR < -.01 ) ? vR = -.01:0;
            ( vG > .01 ) ? vG = .01:
            ( vG < -.01 ) ? vG = -.01:0;

            cTra.redMultiplier += vR;
            cTra.blueMultiplier += vG;
            ( cTra.redMultiplier > .9 ) ? cTra.redMultiplier = .9:
            ( cTra.redMultiplier < .5 ) ? cTra.redMultiplier = .5:cTra.redMultiplier;
            ( cTra.blueMultiplier > .9 ) ? cTra.blueMultiplier = .9:
            ( cTra.blueMultiplier < .5 ) ? cTra.blueMultiplier = .5:cTra.blueMultiplier;         
        }
    }
}
class VectorDat {
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var ax:Number = 0;
    public var ay:Number = 0;
    public var px:Number;
    public var py:Number;

    function VectorDat( px:Number, py:Number ) {
        this.px = px;
        this.py = py;
    }
}