Circle Placement
♥0 |
Line 63 |
Modified 2011-02-09 00:27:00 |
MIT License
archived:2017-03-10 04:03:07
ActionScript3 source code
/**
* Copyright greentec ( http://wonderfl.net/user/greentec )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1dro
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import com.bit101.components.Label;
public class CirclePlacement extends Sprite {
public var circle:Circle;
public var circs:Array=[];
public var num:uint=15;
public var H:Number=stage.stageHeight;
public var W:Number=stage.stageWidth;
public var _sumLabel:Label;
public function CirclePlacement() {
addEventListener(Event.ENTER_FRAME, onAdd);
_sumLabel = new Label(this, 17, 36, "Num : 0");
}
public function onAdd(e:Event):void
{
var sw:Boolean=false;
circle=new Circle();
circle.x=Math.random()*W;
circle.y=Math.random()*H;
var circ2:Circle;
var i:int;
if(circs.length==0)
{
addChild(circle);
circs.push(circle);
}
else
{
for(i=circs.length-1;i>-1;i--)
{
circ2=circs[i];
if(circ2.hitTestObject(circle)==true)
{
sw=true;
}
}
if(sw==false)
{
addChild(circle);
circs.push(circle);
_sumLabel.text="Num : "+circs.length;
}
}
if(circs.length==num)
{
removeEventListener(Event.ENTER_FRAME, onAdd);
}
}
}
}
import flash.display.Sprite;
class Circle extends Sprite
{
public var r:Number, color:Number;
public function Circle(r:Number=0, color:uint=0x333333)
{
r=Math.random()*10+35;
this.graphics.lineStyle(0,0);
this.graphics.drawCircle(0,0,r);
}
}