forked from: forked from: forked from: forked from: forked from: Grid Rotation
MainStage
/**
* Copyright hashito ( http://wonderfl.net/user/hashito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/PYce
*/
// forked from hashito's forked from: forked from: forked from: forked from: Grid Rotation
// MainStage
package {
import flash.display.Sprite;
[SWF(frameRate=60,width=456,height=456)]
public class MainStage extends Sprite {
public function MainStage(){
addChild(new Main());
}
}
}
//---------------main---------------------
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.geom.ColorTransform;
import flash.events.Event;
import net.hires.debug.Stats;
// main class
class Main extends Sprite{
private var _canvas : BitmapData;
private var _show : Sprite;
private var _circle1:Circle;
private var _circle2:Circle;
//Constructor
public function Main() {addEventListener(Event.ADDED_TO_STAGE, init);}
//init
public function init(e:*):void{
//canvas object init
_canvas = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0);
addChildAt( new Bitmap( _canvas ) ,0);
_circle1=new Circle(20,0x00ff00);
_circle1.x=100;
_circle1.y=100;
addChild(_circle1);
_circle2=new Circle(30,0xff0000);
_circle2.x=200;
_circle2.y=200;
addChild(_circle2);
//show object init
_show = new Sprite()
_show.addChild(_circle1);
_show.addChild(_circle2);
//events
addEventListener( Event.ENTER_FRAME, update );
//var s:Stats = new Stats();
//addChild(s);
}
//the loop
private function update( evt:Event ) : void {
_circle1.x=mouseX;
_circle1.y=mouseY;
Circle.Draw();
_canvas.colorTransform( _canvas.rect, new ColorTransform( 0.99, 0.99, 0.99 ) );
_canvas.applyFilter(_canvas, _canvas.rect, new Point(), new BlurFilter(2, 2));
_canvas.draw( _show );
}
}
class Circle extends Sprite{
private static var fellow:Array = new Array();
private static const RAD_GAP:Number = Math.PI * 45 / 180 ;
private static var wkp:Point=new Point();
private static var test:Sprite=new Sprite();
// draw
public static function Draw():void{
test.graphics.beginFill(0xffffff);
test.graphics.drawCircle(0,0,2);
Sprite(fellow[0]).parent.addChild(test);
for each(var a:Circle in fellow){
for each(var b:Circle in fellow){
if( a != b ){
var dx:Number = a.x - b.x;
var dy:Number = a.y - b.y;
var arad:Number = Math.atan2(dy,dx);
var brad:Number = Math.atan2(dy,dx);
var centerx:Number = (b.x - a.x) / 2;
var centery:Number = (b.y - a.y) / 2;
wkp.x = centerx;
wkp.y = centery;
wkp = a.localToGlobal(wkp);
test.x=wkp.x;
test.y=wkp.y;
a.draw();
a.graphics.moveTo(Math.cos(arad + RAD_GAP ) * a.Size,Math.sin(arad + RAD_GAP) * a.Size);
wkp.x = b.x - Math.cos(brad - RAD_GAP) * b.Size;
wkp.y = b.y - Math.sin(brad - RAD_GAP) * b.Size;
wkp = a.globalToLocal(wkp);
a.graphics.curveTo(centerx,centery,wkp.x,wkp.y);
a.graphics.lineTo(Math.cos(arad - RAD_GAP) * a.Size,Math.sin(arad - RAD_GAP) * a.Size);
wkp.x = b.x - Math.cos(brad+RAD_GAP) * b.Size;
wkp.y = b.y - Math.sin(brad+RAD_GAP) * b.Size;
wkp = a.globalToLocal(wkp);
a.graphics.curveTo(centerx,centery,wkp.x,wkp.y);
}
}
}
}
private var size:int;
private var color:int;
public function get Size():int{ return size;}
public function get Color():int{return color;}
public function Circle(size:int=100,color:int=0x00ff00) {
this.size = size;
this.color = color;
addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(e:Event):void{
fellow.push(this);
draw();
}
public function draw():void{
this.graphics.clear()
this.graphics.lineStyle(1,color)
this.graphics.beginFill(color);
this.graphics.drawCircle(0,0,size);
}
}