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: Liquid10000

ひさびさフォーク。普通の書き方でArray10万
コピペしたのでDiffがあれだけど、変えたのは
Array VectorDat lock,unlock setPixel ぐらい
Get Adobe Flash player
by nutsu 15 Apr 2009
// forked from zin0086's Liquid10000
// ひさびさフォーク。普通の書き方でArray10万
// コピペしたのでDiffがあれだけど、変えたのは
// Array VectorDat lock,unlock setPixel ぐらい
package {

    import flash.display.Stage;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.ColorTransform;
    import flash.geom.Rectangle;
    import flash.events.Event;
    import flash.events.MouseEvent;

    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")];
    public class Liquid extends Sprite {

        private const nums:uint = 100000;
        private var bmpDat:BitmapData;
        private var vectorDat:BitmapData;
        private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
        private var bmp:Bitmap;
        private var vectorList:Array;
        private var rect:Rectangle;
        private var cTra:ColorTransform;
        	
        public function Liquid() {
            initialize();
        }
        private function initialize():void {

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.frameRate = 60;
            bmpDat= new BitmapData( 465, 465, false, 0x000000 );
            vectorDat= new BitmapData( 465, 465, false, 0x000000 );
            randomSeed= Math.floor( Math.random() * 0xFFFF );
            vectorDat.perlinNoise( 230, 230, 4,randomSeed, false, true, 1|2|0|0 );

            bmp= new Bitmap( bmpDat );
            addChild( bmp );
			
            rect = new Rectangle( 0, 0, 465, 465 )
            cTra = new ColorTransform( 0, .8, .8, .9 );
			
            vectorList = [];
            for (var i:uint = 0; i < nums; i++) {
                var px:Number = Math.random()*465;
        	var py:Number = Math.random()*465;
        	vectorList.push( new VectorDat(px,py) );
            }
            addEventListener( Event.ENTER_FRAME, loop );
            stage.addEventListener( MouseEvent.CLICK, resetFunc );
        }
        private function loop( e:Event ):void {
            bmpDat.lock();
            bmpDat.colorTransform( rect, cTra );
            var len:uint = vectorList.length;
            for (var i:uint = 0; i < len; i++) {

                var dots:VectorDat = vectorList[i];
        	var col:Number = vectorDat.getPixel( dots.px, dots.py );
        	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 function resetFunc(e:MouseEvent):void{
            randomSeed= Math.floor( Math.random() * 0xFFFF );
            vectorDat.perlinNoise( 230, 230, 4,randomSeed, false, true, 1|2|0|0 );
            vectorList= [];
        		
            for (var i:uint = 0; i < nums; i++) {
                var px:Number = Math.random()*465;
        	var py:Number = Math.random()*465;
        	vectorList.push( new VectorDat( px, py ) );
            }
        }
    }
}

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;
    }
}