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

Connect The Dots

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

package {

	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;


	[SWF(width = 500, height = 500)]

       public class ConnectTheDots extends MovieClip {
		private const TWO_PI:Number =  Math.PI * 2;
		private var centerX:Number;
		private var centerY:Number;


               public function ConnectTheDots(){
                  // init
			centerX = stage.stageWidth / 2;
			centerY = stage.stageHeight / 2;
			addEventListener(Event.ENTER_FRAME, onLoop);
			

               }
               // private methods

		private function onLoop(evt:Event):void{
			// data
			var points:Array = [];
			var i:int = 0;
			var pointNum : int = Math.max(2,int(mouseX / 12))
			
			var radius:Number = 200;
			var step:Number = TWO_PI / pointNum;
			var theta:Number = step / 2;
			for (i = 0; i<pointNum; i++){
				var xp:Number = centerX + radius * Math.cos(theta);
				var yp:Number = centerY + radius * Math.sin(theta);
				points[i] = new Point(xp, yp);
				theta += step;
			}
			// render
			graphics.clear();
			graphics.lineStyle(0,0);
			for ( i = 0; i<pointNum; i++){
		     var a:Point = points[i];
		     for (var j:int = i+1; j<pointNum; j++){
		        var b:Point = points[j];
		         
			       graphics.drawCircle(a.x, a.y, 10);
			       graphics.moveTo(a.x, a.y);
			       graphics.lineTo(b.x, b.y);
		       
		     }
                     
		   }
                  graphics.drawCircle(a.x, a.y, 10);
		}
       }
}