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

Get Adobe Flash player
by peko 17 Jun 2009
// forked from nulldesign's Liquid10000
package {

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.utils.setTimeout;


	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")];

	public class Liquid extends Sprite {

		private const nums:uint = 10000;
		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 const IMAGE_URL:String = "http://img-fotki.yandex.ru/get/3506/gasubasu.23/0_a6be_d4007aaf_XL";
		
		private var image:Bitmap;
		private var imageData:BitmapData;

		public function Liquid() {
			var req:URLRequest = new URLRequest(IMAGE_URL);
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);    
			loader.load( req, new LoaderContext(true));
			
			// take a capture after 10 sec
			//Wonderfl.capture_delay( 10 );
			//setTimeout(function():void{Wonderfl.capture(stage);},10000);
            
        }
        
		public function loadComplete(e:Event = null):void {
                        e.target.removeEventListener(Event.COMPLETE, loadComplete);
			
			image = e.target.loader.content as Bitmap;
			imageData = image.bitmapData;
			
			initialize()			
			
		}

		
		
		
		private function initialize():void {

			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			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.99, .99, .99, .99 );

			vectorList= new Array();

			for (var i:uint = 0; i < nums; i++) {
    
				var px:Number = Math.random()*465;
				var py:Number = Math.random()*465;
				
                                var ic:uint = imageData.getPixel(px,py+200);
				var rr:int = (ic >> 16 & 0xff);
				var gg:int = (ic >>  8 & 0xff);
				var bb:int = (ic >>  0 & 0xff);

				var av:Point = new Point( 0, 0 );
				var vv:Point = new Point( 0, 0 );
				var pv:Point = new Point( px, py );
				var hoge:VectorDat = new VectorDat( av, vv, pv, rr, gg, bb);
				vectorList.push( hoge );
			}
			addEventListener( Event.ENTER_FRAME, loop );
			stage.addEventListener( MouseEvent.CLICK, resetFunc );
		}
		private function loop( e:Event ):void {
			//bmpDat.colorTransform( rect, cTra );

			var list:Array = vectorList;
			var len:uint = list.length;
			for (var i:uint = 0; i < len; i++) {

				var dots:VectorDat = list[i];

				var col:Number = vectorDat.getPixel( dots.pv.x, dots.pv.y );
				var r:uint = (col >> 16 & 0xff)// + ((dots.rr>>1));
				var g:uint = (col >>  8 & 0xff)// + ((dots.bb>>1));
				//var b:uint = col & 0xff;

				dots.av.x += ( r - 128 ) * .0001;
				dots.av.y += ( g - 128 ) * .0001;
				dots.vv.x += dots.av.x;
				dots.vv.y += dots.av.y;
				dots.pv.x += dots.vv.x;
				dots.pv.y += dots.vv.y;

				var _posX:Number = dots.pv.x;
				var _posY:Number = dots.pv.y;

				dots.av.x *= .96;
				dots.av.y *= .96;
				dots.vv.x *= .92;
				dots.vv.y *= .92;
				
				var ic:uint = imageData.getPixel(dots.pv.x,dots.pv.y+200);
				dots.rr -= (dots.rr - (ic >> 16 & 0xff))/100;
				dots.gg -= (dots.gg - (ic >>  8 & 0xff))/100;
				dots.bb -= (dots.bb - (ic >>  0 & 0xff))/100;
				
				( _posX > 465 )?dots.pv.x = 0:
				( _posX < 0 )?dots.pv.x = 465:0;
				( _posY > 465 )?dots.pv.y = 0:
				( _posY < 0 )?dots.pv.y = 465:0;
	
				bmpDat.fillRect( new Rectangle( dots.pv.x, dots.pv.y, 1, 1), (dots.rr<<16) | (dots.gg<<8) | (dots.bb<<0));

			}
		}

		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= new Array();
			
			for (var i:uint = 0; i < nums; i++) {

				var px:Number = Math.random()*465;
				var py:Number = Math.random()*465;

                                var ic:uint = imageData.getPixel(px,py+200);
    				var rr:int = (ic >> 16 & 0xff);
				var gg:int = (ic >>  8 & 0xff);
				var bb:int = (ic >>  0 & 0xff);

				var av:Point = new Point( 0, 0 );
				var vv:Point = new Point( 0, 0 );
				var pv:Point = new Point( px, py );

				var hoge:VectorDat = new VectorDat( av, vv, pv, rr, gg, bb);

				vectorList.push( hoge );
			}
		}
	}
}

import flash.geom.Point;
class VectorDat {

	public var vv:Point;
	public var av:Point;
	public var pv:Point;
	public var rr:int;
	public var bb:int;
	public var gg:int;

	function VectorDat( _av:Point, _vv:Point, _pv:Point, _rr:int, _gg:int, _bb:int ) {
		vv = _vv;
		av = _av;
		pv = _pv;

                rr = _rr;
                gg = _gg;
                bb = _bb;
	}
}