标签:
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="5")] 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 public function Star(len:int=5,radius:Number=50,dis:Number=20,lineColor:uint=0xff0000,fillColor:uint=0x00ffff,isFill:Boolean=false){ 52 if(len<=1){ 53 trace("星形边数至少为2"); 54 return; 55 } 56 this.graphics.lineStyle(1,lineColor); 57 if(isFill){ 58 this.graphics.beginFill(fillColor) 59 } 60 this.graphics.moveTo(dis,0); 61 for(var i:int = 1;i<=len*2;i++){ 62 _b?[_x=dis*Math.cos(i*Math.PI*2/(len*2)),_y=dis*Math.sin(i*Math.PI*2/(len*2))]:[_x=radius*Math.cos(i*Math.PI*2/(len*2)),_y=radius*Math.sin(i*Math.PI*2/(len*2))]; 63 this.graphics.lineTo(_x,_y); 64 _b=!_b; 65 } 66 if(len%2!=0){ 67 this.rotation = 90; 68 } 69 } 70 }
标签:
原文地址:http://www.cnblogs.com/frost-yen/p/4795557.html