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

Drop

...
@author Rigard Kruger
Get Adobe Flash player
by rigard 07 Jan 2009
    Embed
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.events.TimerEvent;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author Rigard Kruger
	 */
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="31")]
	public class Drop extends Sprite 
	{
		
		private var _balls:Vector.<Ball>;
		
		private var _input:Sprite;
		private var _output:Bitmap;
		
		public function Drop()
		{
			
			_balls = new Vector.<Ball>;
			
			_input = new Sprite();
			
			_output = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000));
			addChild(_output);
			
			var updateTimer:Timer = new Timer(30);
			updateTimer.addEventListener(TimerEvent.TIMER, update);
			updateTimer.start();
			
			var addBallTimer:Timer = new Timer(50);
			addBallTimer.addEventListener(TimerEvent.TIMER, addBall);
			addBallTimer.start();
			
		}
		
		private function update(e:TimerEvent) : void
		{
			
			var numBalls:int = _balls.length;
			for (var i:int = 0; i < numBalls; i++)
			{
				var ball:Ball = _balls[i];
				ball.update();
				if (ball.y > stage.stageHeight)
				{
					_input.removeChild(ball);
					_balls.splice(i--, 1);
					numBalls--;
				}
				
				if (ball.hitTestPoint(stage.mouseX, stage.mouseY))
				{
					ball.vx = 0;
					ball.vy = 0;
					ball.ax = Math.random() * 0.4 - 0.2;
					ball.ay = Math.random() * 0.4 - 0.2;
				}
			}
			
			var bd:BitmapData = _output.bitmapData;
			bd.draw(_input, null, null, BlendMode.ADD);
			bd.draw(_input, null, null, BlendMode.SCREEN);
			bd.applyFilter(bd, new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), new Point(), new BlurFilter());
			var ct:ColorTransform = new ColorTransform();
			ct.alphaMultiplier = 0.9;
			bd.colorTransform(new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), ct);
		}
		
		private function addBall(e:TimerEvent) : void
		{
			var ball:Ball = new Ball();
			ball.x = Math.random() * 465;
			ball.y = -20;
			_input.addChild(ball);
			
			_balls.push(ball);
		}
		
	}
	
}
import flash.display.Sprite;

class Ball extends Sprite
{
	
	public var ay:Number = 0.2;
	public var vy:Number = 0;
	public var ax:Number = 0;
	public var vx:Number = 0;
	
	public function update() : void
	{
		vy += ay;
		y += vy;
		
		ax += Math.random() * 0.05 - 0.025;
		vx += ax;
		x += vx;
	}
	
	public function Ball()
	{
		graphics.beginFill(Math.random() * 0xffffff, 1);
		graphics.drawCircle(0, 0, Math.random() * 20 + 5);
		graphics.endFill();
	}
	
}