比如我要把圆形切成30等分,代码如下:
import flash.display.Shape;
var k:int =30;//切成30等分
var cx:Number = 375/2;
var cy:Number = 667/2;
var cr:Number =cx-10;
var line:Shape = new Shape();
line.graphics.lineStyle(1,RandRGB());
function draw1(x1:Number,y1:Number):void{
line.graphics.moveTo(cx,cy);
line.graphics.lineTo(x1,y1);
}
var okx:Number;
var oky:Number;
var d:Number;
for(var i:int=0;i<k;i++){
var dd:int = 360/k;
var d2:Number = i*dd;
if(d2==0){
okx = cx;
oky = cy-cr;
}else if(d2==180){
okx = cx;
oky = cy+cr;
}else if(d2==270){
okx = cx-cr;
oky = cy;
}else if(d2==90){
okx = cx+cr;
oky = cy;
}else{
if(d2<90){
d = d2*Math.PI/180;
okx = cx+cr*Math.sin(d);
oky = cy-cr*Math.cos(d);
}
else if(d2>90&&d2<180)
{
d= (d2-90)*Math.PI/180;
okx = cx+cr*Math.cos(d);
oky = cy+cr*Math.sin(d);
}else if(d2>180&&d2<270)
{
d = (360-90-d2)*Math.PI/180;
okx = cx-cr*Math.cos(d);
oky = cy+cr*Math.sin(d);
}else if(d2>270){
d = (360-d2)*Math.PI/180;
okx = cx-cr*Math.sin(d);
oky = cy-cr*Math.cos(d);
}
}
draw1(okx,oky);
//trace(cx,cy,cr,okx,oky,d2,d);
}
var c:Shape = new Shape();
c.graphics.lineStyle(2,0);
c.graphics.drawCircle(cx,cy,cr);
c.graphics.drawCircle(cx,cy,cr*0.8);
c.graphics.drawCircle(cx,cy,cr*0.64);
addChild(line);
addChild(c);
function RandRGB():uint {
return (Math.random() * 0xffffff + 0x000000);
}