1 Package2 {3 ImportFlash.display.Sprite;4 Importflash.events.Event;5 6 /**7 * @author Frost.yen8 * @e-mail [email protected]9 * @create 2015-9-9 pm 4:47:50Ten * One */ A[SWF (width="1024x768", height="1024x768", framerate="5")] - Public classDrawstarextendsSprite - { the Public functionDrawstar () - { - initviews (); - initeventlisteners (); + } - Private functionInitviews ():void + { A Draw (); at } - Private functionIniteventlisteners ():void - { - This. AddEventListener (Event.enter_frame,onfresh); - } - Private functionOnfresh (e:event):void in { - This. Removechildren (); to Draw (); + } - Private functionDraw ():void the { * for(vari:int=0;i<64;i++){ $ varStar:star =NewStar (Math.random () *10+2,50,20,math.random () *255-math.random () *0xffffff,math.random () *0xffffff-math.random () * 255,true);Panax NotoginsengStar.x = i%8*100+100; -Star.y = Math.floor (i/8) *100+100; the This. AddChild (star); + } A } the } + } - ImportFlash.display.Sprite; $ $ classStarextendsSprite - { - Private var_b:Boolean; the Private var_x: Number; - Private var_y: Number;Wuyi Public functionStar (Len:int=5,radius: Number=50,dis: Number=20,linecolor:uint=0xff0000,fillcolor:uint=0x00ffff,isfill:Boolean=false){ the if(len<=1){ -Trace"star Edge number is at least 2"); Wu return; - } About This. Graphics.linestyle (1, LineColor); $ if(Isfill) { - This. Graphics.beginfill (FillColor) - } - This. Graphics.moveto (dis,0); A for(varI:int = 1;i<=len*2;i++){ +_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))]; the This. Graphics.lineto (_x,_y); -_b=!_b; $ } the if(len%2!=0){ the This. rotation = 90; the } the } -}
[ActionScript 3.0] AS3 Drawing star Shape