1 package 2 { 3 import flash.display.Sprite; 4 import flash.events.Event; 5 6 /** 7 * @author Frost.Yen 8 * @E-mail 871979853@qq.com 9 * @create 2015-9-9 下午4:47:50 10 * 11 */ 12 [SWF(width="1024",height="1024",frameRate="3")] 13 public class DrawStar extends Sprite 14 { 15 public function DrawStar() 16 { 17 initViews(); 18 initEventListeners(); 19 } 20 private function initViews():void 21 { 22 draw(); 23 } 24 private function initEventListeners():void 25 { 26 this.addEventListener(Event.ENTER_FRAME,onFresh); 27 } 28 private function onFresh(e:Event):void 29 { 30 this.removeChildren(); 31 draw(); 32 } 33 private function draw():void 34 { 35 for(var i:int=0;i<64;i++){ 36 var star:Star = new Star(Math.random()*10+2,50,20,Math.random()*255-Math.random()*0xffffff,Math.random()*0xffffff-Math.random()*255,true); 37 star.x = i%8*100+100; 38 star.y = Math.floor(i/8)*100+100; 39 this.addChild(star); 40 } 41 } 42 } 43 } 44 import flash.display.Sprite; 45 46 class Star extends Sprite 47 { 48 private var _b:Boolean; 49 private var _x:Number; 50 private var _y:Number; 51 /** 52 * 53 * @param len 星形边数 54 * @param radius1 五角星中心点离较远顶点的距离(可看作五角星外接圆的半径) 55 * @param radius2 五角星中心点离较近顶点的距离(可看作五角星内接圆的半径) 56 * @param lineColor 线条颜色 57 * @param fillColor 填充颜色 58 * @param isFill 是否填充 59 */ 60 public function Star(len:int=5,radius1:Number=50,radius2:Number=20,lineColor:uint=0xff0000,fillColor:uint=0x00ffff,isFill:Boolean=false){ 61 if(len<=1){ 62 trace("星形边数至少为2"); 63 return; 64 } 65 this.graphics.lineStyle(1,lineColor); 66 if(isFill){ 67 this.graphics.beginFill(fillColor) 68 } 69 this.graphics.moveTo(radius2,0); 70 for(var i:int = 1;i<=len*2;i++){ 71 _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))]; 72 this.graphics.lineTo(_x,_y); 73 _b=!_b; 74 } 75 if(len%2!=0){ 76 this.rotation = 90; 77 } 78 } 79 }