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

flash on 2009-11-19

Get Adobe Flash player
by kenz 19 Nov 2009
/**
 * Copyright kenz ( http://wonderfl.net/user/kenz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tSBb
 */

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;

	
	import net.hires.debug.Stats;

	[ SWF( width="465", height="465", backgroundColor="0xffffff", frameRate="60" ) ]
	
	public class Dots extends Sprite
	{
		private const STAGE_WIDTH:uint = 465;
		private const STAGE_HEIGHT:uint = 465;
		
		private const DISTANCE:uint = 50;
		
		
		private var _particleList:Array;
		private var _length:uint;

		private var _canvas:BitmapData;
		
		private var _transform:ColorTransform;
		
		private var _rect:Rectangle;
		
		private var _time:Number;
		private var _currentTime:Number;
		private var _prevTime:Number;
		
		private var _distance:Number;
		
		private var _prevXpt:int;
		private var _prevYpt:int;



		public function Dots()
		{
			_particleList = [];
			
			//------------------------------
			_canvas = new BitmapData( STAGE_WIDTH, STAGE_HEIGHT, true, 0x00ffffff );
			
			addChild( new Bitmap( _canvas ) );
			
			for ( var i:uint = 50; i < STAGE_WIDTH - 50; i += 4 )
			{
				for ( var j:uint = 50; j < STAGE_HEIGHT - 50; j += 4 )
				{
					var _dot:Dot = new Dot( i, j );
					_particleList.push( _dot );
				}
			}
			
			_prevTime = new Date().getTime();
			
			//------------------------------
			_transform = new ColorTransform( 1, 1, 1, .9 );
			
			//------------------------------
			_rect = new Rectangle( 0, 0, STAGE_WIDTH, STAGE_HEIGHT );
			
			//------------------------------
			stage.addEventListener( Event.ENTER_FRAME, onEnterHandler, false, 0, true );
			
			//------------------------------
			var debug:Stats = new Stats();
			addChild( debug )
		}




		private function onEnterHandler( e:Event ):void
		{
			update();
		}



		private function update():void
		{
			_canvas.lock();
			
			//------------------------------
			_canvas.colorTransform( _rect, _transform );
			
			//------------------------------
			_currentTime = new Date().getTime();
			_time = ( _currentTime - _prevTime ) / 1000;
			
			//------------------------------
			_length = _particleList.length;
			for ( var i:uint = 0; i < _length; i++ )
			{
				var _dot:Dot = _particleList[i];
				
				//------------------------------
				_dot.x += _dot.vx * _time + 0.5 * _dot.ax * _time * _time;
				_dot.y += _dot.vy * _time + 0.5 * _dot.ay * _time * _time;
				
				//------------------------------
				_dot.vx += _dot.ax * _time;
				_dot.vy += _dot.ay * _time;
				
				//------------------------------
				_dot.vx *= .1;
				_dot.vy *= .1;
				
				//------------------------------
				_dot.ax = 0;
				_dot.ay = 0;
				
				_dot.ax += ( _dot.xpt - _dot.x ) * 128;
				_dot.ay += ( _dot.ypt - _dot.y ) * 128;
				
				//------------------------------
				_distance = Math.sqrt( Math.pow( _dot.x - mouseX, 2 ) + Math.pow( _dot.y - mouseY, 2 ) );
				
				//------------------------------
				if ( _distance < DISTANCE )
				{
					var _r:Number = Math.ceil( Math.random() * 64 );
					//------------------------------
					var _p:Number = Math.round( ( DISTANCE - _distance ) / DISTANCE * 1024 );
					//------------------------------
					_dot.ax += ( _dot.x - ( mouseX + ( _prevXpt - mouseX ) * _r ) ) * _p;
					_dot.ay += ( _dot.y - ( mouseY + ( _prevYpt - mouseY ) * _r ) ) * _p;
				}
				
				if ( Math.sqrt( Math.pow( _dot.xpt - _dot.x, 2 ) + Math.pow( _dot.ypt - _dot.y, 2 ) ) < 1 )
				{
					_dot.x = _dot.xpt;
					_dot.y = _dot.ypt;
				}
				
				var _color:uint = ( _dot.x >= 50 && _dot.x <= STAGE_WIDTH - 50 && _dot.y >= 50 && _dot.y <= STAGE_HEIGHT - 50 ) ? 0xffff6600 : Math.random() * 0xffffffff;

				_canvas.setPixel32( _dot.x, _dot.y, _color );
			}
			//------------------------------
			_canvas.unlock();
			
			//------------------------------
			_prevTime = _currentTime;
			//------------------------------
			_prevXpt = mouseX;
			_prevYpt = mouseY;
		}
	}
}


class Dot
{
	public var xpt:Number;
	public var ypt:Number;
	
	public var x:Number;
	public var y:Number;
	public var vx:Number;
	public var vy:Number;
	public var ax:Number;
	public var ay:Number;
	
	public function Dot( x:Number = 0, y:Number = 0 )
	{
		this.xpt = x;
		this.ypt = y;
		
		this.x = x;
		this.y = y;
		this.vx = 0;
		this.vy = 0;
		this.ax = 0;
		this.ay = 0;
	}
}