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

//////////////////////////////////////////////////////////////////////////////
外部画像を1pxごとに表示
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by aznFanBoy 09 Sep 2009
// forked from twistcube's ParticleEffect
////////////////////////////////////////////////////////////////////////////////
//
//  外部画像を1pxごとに表示
//
////////////////////////////////////////////////////////////////////////////////
package
{
	import flash.display.* ;
	import flash.events.* ;
	import flash.filters.ColorMatrixFilter;
	import flash.net.* ;
	import flash.system.* ;
	import flash.utils.getTimer ;
	
	[SWF(width="500", height="500", backgroundColor="0xFFFFFF", frameRate="40")]
	public class ParticleEffect extends Sprite
	{
		private var _loader:Loader ;
		private var _loaderInfo:LoaderInfo ;
		private var _particleList:Array = new Array( ) ;
		private var _bitmapList:ParticleBitmap ;
		private var _startTime:int ;
		
		public function ParticleEffect( )
		{
			init( ) ;
                        inittrace(stage)
		}
		
		private function init( ):void
		{
                  stage.scaleMode = StageScaleMode.NO_SCALE ;
                  stage.align = StageAlign.TOP_LEFT ;
                  stage.quality = StageQuality.LOW ;
            
                  Security.loadPolicyFile( "http://www.twist-cube.com/wonderfl/crossdomain.xml" ) ;
            
                  var loaderContext:LoaderContext = new LoaderContext( ) ;
                  loaderContext.checkPolicyFile = true ;
            
                  _loader = new Loader( ) ;
                  _loader.load( new URLRequest( "http://www.twist-cube.com/wonderfl/logo02.png" ), loaderContext ) ;
            
                  _loaderInfo = _loader.contentLoaderInfo ;
                  _loaderInfo.addEventListener( Event.COMPLETE, onLoadComplete ) ;
		}
		
		private function onLoadComplete( event:Event ):void
		{
                        trace("Load Complete.")
			_loaderInfo.removeEventListener( Event.COMPLETE, onLoadComplete ) ;
			_bitmapList = new ParticleBitmap( _loader ) ;
			
			var nStartX:Number = Math.floor( ( stage.stageWidth - _loader.width ) / 2 ) ;
			var nStartY:Number = Math.floor( ( stage.stageHeight - _loader.height ) / 2 ) ;
			
			/*

			_loader.x = nStartX ;
			_loader.y = nStartY ;
			
			addChild( _loader ) ;
			
			var grayScale:Array = 
				[
					1/3, 1/3, 1/3,   0, 0,
					1/3, 1/3, 1/3,   0, 0,
					1/3, 1/3, 1/3,   0, 0,
					  0,   0,   0, .05, 0
				] ;
			
			_loader.filters = [ new ColorMatrixFilter( grayScale ) ] ;
			
                        */
			
			var nLength:uint = _bitmapList.list.length ;
			var bmp:Bitmap ;
			var current:Object ;
			for ( var i:uint = 0; i < nLength; i++ )
			{
				current = _bitmapList.list[ i ] ;
				bmp = current.bitmap ;
				//bmp.alpha = 0 ;
				bmp.x = nStartX + current.x - 5000 * Math.random( ) + 2500 ;
				bmp.y = nStartY + current.y - stage.stageHeight - 5000 * Math.random( ) ;
				addChild( bmp ) ;
				_particleList.push( bmp ) ;
			}
			
			//_particleList.reverse( ) ;
			//_bitmapList.list.reverse( ) ;
			
			_startTime = getTimer( ) ;
			addEventListener( Event.ENTER_FRAME, onRender );
		}
		
		private function onRender( event:Event ):void
		{
			var nStartX:Number = Math.floor( ( stage.stageWidth - _loader.width ) / 2 ) ;
			var nStartY:Number = Math.floor( ( stage.stageHeight - _loader.height ) / 2 ) ;
			var nLength:uint = _particleList.length ;
			var bmp:Bitmap ;
			var current:Object ;
			var now:int = getTimer( ) ;
			var wait:Number ;
			for ( var i:uint = 0; i < nLength; i++ ) 
			{
				current = _bitmapList.list[ i ] ;
				
				// 下から吸着させる
				wait = ( 1 - ( current.y / _loader.height ) ) * 4000 ;
				
				if ( _startTime + wait > now ) continue ; 
				
				bmp = _particleList[ i ] ;
				bmp.x += ( ( nStartX + current.x ) - bmp.x ) * .2 ;
				bmp.y += ( ( nStartY + current.y ) - bmp.y ) * .2 ;
				//bmp.alpha += ( 1 - bmp.alpha ) * .1 ;
			}
		}
	}
}


import flash.display.* ;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Rectangle;

class ParticleBitmap
{
	private var _originImage:DisplayObject ;
	private var _list:Array = new Array( ) ;
	
	public function ParticleBitmap( _originImage:DisplayObject )
	{
		this._originImage = _originImage ;
		init( ) ;
	}
	
	private function init( ):void
	{
                trace("Particle Bitmap Initalized.")
		var nW:Number = _originImage.width ;
		var nH:Number = _originImage.height 
		var originBitmapData:BitmapData = new BitmapData( _originImage.width, _originImage.height, true, 0x00FFFFFF ) ;
		originBitmapData.draw( _originImage ) ;
		
		var originBitmap:Bitmap = new Bitmap( originBitmapData ) ;
		
		for ( var i:uint = 0; i < nW; i++ )
		{
			for ( var j:int = 0; j < nH; j++ )
			{
				var color:uint = originBitmapData.getPixel32( i, j ) ;
				if ( color == 0 ) continue ;
				var bmpData:BitmapData = new BitmapData( 1, 1, true, color ) ;
				var bmp:Bitmap = new Bitmap( bmpData ) ;
				_list.push( { bitmap:bmp, x:i, y:j } ) ;
			}
		}
	}
	
	public function get list( ):Array
	{
		return _list ;
	}
	
	public function set list( _list:Array ):void
	{
		this._list = _list ;
	}
}

/////  WONDERFL TRACE /////
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
function inittrace(s:Stage):void
{
    WTrace.initTrace(s);
}
//global trace function
var trace:Function;
//wtreace class
class WTrace
{
        private static var FONT:String = "Fixedsys";
        private static var SIZE:Number = 12;
        private static var TextFields:Array = [];
        private static var trace_stage:Stage;
        
        public static function initTrace(stg:Stage):void
        {
            trace_stage = stg;
            trace = wtrace;
        }
        
        private static function scrollup():void
        {
            // maximum number of lines: 100
            if (TextFields.length > 100) 
            {
                var removeme:TextField = TextFields.shift();
                trace_stage.removeChild(removeme);
                removeme = null;
            }
            for(var x:Number=0;x<TextFields.length;x++)
            {
                (TextFields[x] as TextField).y -= SIZE*1.2;
            }
        }
    
        public static function wtrace(... args):void
        {
        
            var s:String="";
            var tracefield:TextField;
            
            for (var i:int;i < args.length;i++)
            {
                // imitating flash:
                // putting a space between the parameters
                if (i != 0) s+=" ";
                s+=args[i].toString();
            }
            
            tracefield= new TextField();
            tracefield.autoSize = "left";
            tracefield.text = s;
            tracefield.y = trace_stage.stageHeight - 20;
            var tf:TextFormat = new TextFormat(FONT, SIZE);
            tracefield.setTextFormat(tf);
            trace_stage.addChild(tracefield);
            scrollup();                      
            TextFields.push(tracefield);
            
        }
}