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

pixelDissolve&DisplacementMapFilter

pixelDissolveとDisplacementMapFilterの組み合わせ
はじめてwonderflを使ってみました
Get Adobe Flash player
by nipx 07 Apr 2010
/**
 * Copyright nipx ( http://wonderfl.net/user/nipx )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/AleI
 */

package {
	
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.system.LoaderContext;
    import flash.geom.*;
    import flash.utils.Timer;
	
	[SWF(width="500", height="375", frameRate="60", backgroundColor="#000000")]
	
	/**
	 * pixelDissolveとDisplacementMapFilterの組み合わせ
	 * はじめてwonderflを使ってみました
	 */	
    public class FlashTest extends Sprite {
    		
        public function FlashTest() {
        	
        		var flower:BitmapData = new BitmapData( 500, 375 );
			var req:URLRequest= new URLRequest( "http://assets.wonderfl.net/images/related_images/4/4a/4a90/4a909cce9e124503598d595e649900469fd256bd" );
			var loader:Loader = new Loader();
			loader.load( req, new LoaderContext(true) );
			loader.contentLoaderInfo.addEventListener( Event.COMPLETE,
            		function(e:Event):void{
        				flower.draw( loader );
        				init();
            		}
            );
            
            
            function init():void{
            		var map:BitmapData		= new BitmapData( 500, 375, true, 0x00000000 );
				var shape:Shape			= new Shape();
				var g:Graphics			= shape.graphics;
				var mat:Matrix			= new Matrix();
				
				mat.createGradientBox( 500, 375 );
				g.beginGradientFill( GradientType.LINEAR, [ 0xFF0000, 0xFF0000 ], [ 1,0 ], [ 0, 255 ], mat );
				g.drawRect( 0,0,500,375 );
				map.draw( shape );

				mat.createGradientBox( 500, 375, 90 * Math.PI / 180 );
				g.clear();
				g.beginGradientFill( GradientType.LINEAR, [ 0x00FF00, 0x00FF00 ], [ 1,0 ], [ 0, 255 ], mat );
				g.drawRect( 0,0,500,375 );
				map.draw( shape, null, null, BlendMode.ADD );
				
				var bg:Bitmap		= new Bitmap( flower );
				var bmd:BitmapData	= new BitmapData( 500, 375, true, 0x00000000 );
				var bmp:Bitmap		= new Bitmap( bmd );
				addChild( bg );
				addChild( bmp );
				
				
				var randomNum:int = Math.floor( Math.random() * int.MAX_VALUE );
				var timer:Timer	= new Timer( 1000/60 );
				timer.addEventListener( TimerEvent.TIMER, onTimer );
				timer.start();
				function onTimer( e:TimerEvent ):void{
   					randomNum = update( randomNum );
				}
				
				
				var temp:BitmapData	= new BitmapData( 500, 375, true, 0x00000000 );
				function update( randomNum:int ):int{
					temp.fillRect( temp.rect, 0x00000000 );
					var i:int = temp.pixelDissolve( flower, flower.rect, new Point( 0,0 ), randomNum, 1000 );
					flower.threshold( temp, flower.rect, new Point(0,0), ">", 0x00000000, 0x00000000 );
					var filter:DisplacementMapFilter = new DisplacementMapFilter( map, new Point( 0,0 ), BitmapDataChannel.RED, BitmapDataChannel.GREEN, 20, 20, DisplacementMapFilterMode.COLOR, 0, 0 );
					bmd.applyFilter( bmd, bmd.rect, new Point( 0,0 ), filter );
					bmd.threshold( bmd, bmd.rect, new Point(0,0), "<", 0x33000000, 0x00000000 );
					bmd.colorTransform( bmd.rect, new ColorTransform( 1,1,1,0.98 ) );
					bmd.draw( temp );
					return i;
				}
            }
            
            
            
        }
    }
}