package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-9-9 下午4:47:50
*
*/
[SWF(width="1024",height="1024",frameRate="3")]
public class DrawStar extends Sprite
{
public function DrawStar()
{
initViews();
initEventListeners();
}
private function initViews():void
{
draw();
}
private function initEventListeners():void
{
this.addEventListener(Event.ENTER_FRAME,onFresh);
}
private function onFresh(e:Event):void
{
this.removeChildren();
draw();
}
private function draw():void
{
for(var i:int=0;i<64;i++){
var star:Star = new Star(Math.random()*10+2,50,20,Math.random()*255-Math.random()*0xffffff,Math.random()*0xffffff-Math.random()*255,true);
star.x = i%8*100+100;
star.y = Math.floor(i/8)*100+100;
this.addChild(star);
}
}
}
}
import flash.display.Sprite;
class Star extends Sprite
{
private var _b:Boolean;
private var _x:Number;
private var _y:Number;
/**
*
* @param len 星形边数
* @param radius1 五角星中心点离较远顶点的距离(可看作五角星外接圆的半径)
* @param radius2 五角星中心点离较近顶点的距离(可看作五角星内接圆的半径)
* @param lineColor 线条颜色
* @param fillColor 填充颜色
* @param isFill 是否填充
*/
public function Star(len:int=5,radius1:Number=50,radius2:Number=20,lineColor:uint=0xff0000,fillColor:uint=0x00ffff,isFill:Boolean=false){
if(len<=1){
trace("星形边数至少为2");
return;
}
this.graphics.lineStyle(1,lineColor);
if(isFill){
this.graphics.beginFill(fillColor)
}
this.graphics.moveTo(radius2,0);
for(var i:int = 1;i<=len*2;i++){
_b?[_x=radius2*Math.cos(i*Math.PI*2/(len*2)),_y=radius2*Math.sin(i*Math.PI*2/(len*2))]:[_x=radius1*Math.cos(i*Math.PI*2/(len*2)),_y=radius1*Math.sin(i*Math.PI*2/(len*2))];
this.graphics.lineTo(_x,_y);
_b=!_b;
}
if(len%2!=0){
this.rotation = 90;
}
}
}