forked from: Connect The Dots
/**
* Copyright Altschuler ( http://wonderfl.net/user/Altschuler )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hHrd
*/
// forked from shapevent's Connect The Dots
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;
private var offset : Number;
public function ConnectTheDots(){
// init
centerX = stage.stageWidth / 2;
centerY = stage.stageHeight / 2;
offset = 0;
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;
offset+=.1;
for (i = 0; i<pointNum; i++){
var xp:Number = centerX + (radius+Math.cos(i+offset)*(mouseY/20)) * Math.cos(theta);
var yp:Number = centerY + (radius+Math.sin(i+offset)*(mouseY/20)) * 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 = 0; j<pointNum; j++){
var b:Point = points[j];
if (a != b){
graphics.drawCircle(a.x, a.y, 10);
graphics.moveTo(a.x, a.y);
graphics.lineTo(b.x, b.y);
}
}
}
}
}
}