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

Proximity step 2

/**
 * Copyright onedayitwillmake ( http://wonderfl.net/user/onedayitwillmake )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/giJu
 */

package 
{
	
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.Event;
	import flash.geom.Matrix;

	[SWF(width="465", height="465", background="#000000")]
	
	public class Proximity extends Sprite
	{
		//Parameters 
        private var _cCount			:int = 0;
        private var _cMax			:int = 60;
		//Rendering
		private var _canvas			:Sprite;
		public	var _canvasGraphics	:Graphics
		//Reference 
		public	var _lastCircle		:Circle; 
		
		public function Proximity()
		{
			stage.quality = StageQuality.MEDIUM;
			
			addChildAt(createBG(), 0);
			addChild(_canvas = new Sprite());
			_canvasGraphics = _canvas.graphics;
			
			addEventListener(Event.ENTER_FRAME, loop);
		}
		
		private function createBG():Sprite
		{
			var matr:Matrix = new Matrix();
			matr.createGradientBox(465, 465, Math.PI / 2, 0, 0);
			
			var bg:Sprite = new Sprite();
			bg.graphics.beginGradientFill
			(
				GradientType.LINEAR, 
				[0xDEDBA7, 0xD13F32], //colors
				[1, 1], //alphas
				[0, 255], //ratios
				matr, //matrix
				SpreadMethod.PAD
			);	
			
			bg.graphics.drawRect(0, 0, 465, 465);
			bg.graphics.endFill();
			
			return bg;
		}
		
		/**
		 * Main program loop
		 */ 
		private function loop(e:Event):void
		{
			draw();
			create();
		}
		
		/**
		 * Creates more circles if we have not reached the maximum count
		 */ 
		public function create():void
		{
			if(Math.random() < 0.05 || _cCount >= _cMax) return;
			
			var c:Circle = new Circle(this);
				c.x = Math.random() * stage.stageWidth;
				c.y = Math.random() * stage.stageHeight;	
			_canvas.addChild(c);
			
			_cCount++;
			if(_lastCircle) c._prev = _lastCircle;
				
			_lastCircle = c;
		}
		
		/**
		 * Draws the proximity field between the circles
		 */ 
		public function draw():void
		{
			_canvas.graphics.clear();
			_canvas.graphics.lineStyle(0.5, 0xffffff, 0.3);
			
			if(_lastCircle == null) return;
			_lastCircle.checkForProximity(_lastCircle._prev);
			
			//Connect
                    //_lastCircle.alpha *= 0.6 + Math.random() * 0.4 
				//	_canvas.graphics.moveTo(_lastCircle.x, _lastCircle.y);
				//	_canvas.graphics.curveTo(c.x, c.y, (c.x - _lastCircle.x) * 0.5, (c.y - _lastCircle.y)*0.5);
		}
	}
}


import flash.display.Shape;
import flash.display.Sprite;

/**
 * Circles that live in the feild
 */
class Circle extends Sprite
{
	private var _radius			:Number = Math.random() * 15 + 5;
	private var _curveModifier	:Number	= Math.random() * 50 - 25;
 	
 	public var _p			:Proximity; //reference
 	public var _prev		:Circle;	//Linked list style behavior
	
	/**
	 * Individual Circles know only the Circle created previously to their own
	 */
	public function Circle(p:Proximity):void
	{
		_p = p;
				
		graphics.beginFill(0x71B095)
		graphics.drawCircle(0, 0, 4);
		graphics.endFill();
		
		graphics.beginFill(0x1A212C, 0.5)
		graphics.drawCircle(0, 0, _radius);
		graphics.endFill();
	}
	
	/**
	 * Check all previous circles for proximity, and do [something]
	 * There is no need for each circle to check the ones ahead, 
	 * because they've already checked against this one.
	 * 
	 * Called recursively for this circle, until the linked list reaches the first circle.
	 * Once it does, it calls checkForProximity on its '_prev'
	 * The sequence repeats until there are no more previous ones
	 * 
	 * @param tc:Circle The 'test circle' we will check against.
	 */ 
	public function checkForProximity(tc:Circle):void
	{
		if(tc == null) return; // This is the first circle created (unless error of course!)
		var d:Number = Math.sqrt((x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y));
		var polarity:int = Math.random() > 0.5 ? 0.5 : -0.5;
		
		if(d < 100)
		{
			_p._canvasGraphics.moveTo(x, y);
			//_p._canvasGraphics.lineTo(tc.x, tc.y);
			//_p._canvasGraphics.curveTo(tc.x, tc.y);
			_p._canvasGraphics.curveTo((x + tc.x) * 0.5, (y + tc.y) * 0.5 + _curveModifier, tc.x, tc.y);
		}
		
		if(tc._prev)
			checkForProximity(tc._prev);
		else if(_prev)
			_prev.checkForProximity(_prev._prev);
	}
	
    public function destroy():void
    {
//         _p._firstCircle = this;
    }	
}