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: forked from: 6 times forked from: Liquid10000

50,000 ぐらいやとなんとか動くかなぁ
高速化のまとめで書いたコードですが、我が子の成長を見るようです【謎】
Get Adobe Flash player
by hacker_q4ift_ht 21 Jan 2010
// forked from hacker_q4ift_ht's forked from: 6 times forked from: Liquid10000
// forked from nulldesign's 6 times forked from: Liquid10000
// forked from clockmaker's forked from: forked from: forked from: forked from: forked from: Liquid10000
// 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
// 50,000 ぐらいやとなんとか動くかなぁ
// 高速化のまとめで書いたコードですが、我が子の成長を見るようです【謎】
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;
    import flash.events.TimerEvent;
    import flash.utils.*;
    import flash.geom.Point;
    import flash.filters.BlurFilter;

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

        private const nums:uint = 30000;
        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;
        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 = 60;
            bmpDat= new BitmapData( 465, 465, false, 0x000000 );
            vectorDat= new BitmapData( 230, 230, false, 0x000000 );
            randomSeed= Math.floor( Math.random() * 0xFFFF );
            vectorDat.perlinNoise( 57, 57, 4,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 = [];
            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 );
            timer = new Timer(100, 0);
            timer.addEventListener(TimerEvent.TIMER, resetFunc);
            timer.start();
        }
        private var filter:BlurFilter = new BlurFilter( 3, 3, 1 );
	private var blurPoint:Point = new Point();
        private function loop( e:Event ):void {
            bmpDat.lock();
            bmpDat.applyFilter( bmpDat, rect, blurPoint, filter );
            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*0.5,  dots.py*0.5);
        	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{
            //randomSeed= Math.floor( Math.random() * 0xFFFF );
            vectorDat.perlinNoise( 116, 116, 2, seed, false, true, 1|2|0|0, false, offset );
            offset[0].x += 1.5;
            offset[1].y += 1.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 ) );
            }*/
            
            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;
    }
}