as3动态画六边形

类代码:
package {
import flash.events.TimerEvent;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.display.Shape;
public class DrawPolygon extends Sprite {
private var xx:Number;
private var yy:Number;
private var rn:Number;
private var bs:uint;
public function DrawPolygon(a:Number=0,b:Number=0,d:uint=3,r:Number=100) {
xx=a;
yy=b;
rn=r;
bs=d;
drawp();
}
private function drawp() {
var coun:uint=0;
var jd:Number=(bs-2)*Math.PI/bs;
var border:Number=rn*Math.sin(Math.PI/bs)*2;
var my_t:Timer=new Timer(100,bs);
var my_shape:Shape=new Shape();
my_shape.graphics.lineStyle(1,255);
my_shape.graphics.moveTo(xx+rn,yy);
my_t.addEventListener(TimerEvent.TIMER,cc);
my_t.addEventListener(TimerEvent.TIMER_COMPLETE,dd);
my_t.start();
this.addChild(my_shape);
function dd(event:TimerEvent) {
my_t.stop();
my_t.removeEventListener(TimerEvent.TIMER,cc);
my_t.removeEventListener(TimerEvent.TIMER_COMPLETE,dd);
}

function cc(event:TimerEvent) {
coun++;
var aa=xx+rn*Math.cos(Math.PI*2/bs*coun);
var bb=yy+rn*Math.sin(Math.PI*2/bs*coun);
my_shape.graphics.lineTo(aa,bb);
}
}
}
}
使用方法:如果要画一个六边形,坐标为100,100,半径为200,可以这样写: import DrawPolygon;
var bb:DrawPolygon=new DrawPolygon(100,100,6,200);
addChild(bb);

你可能感兴趣的:(Actionscript)