画扇形代码
程序员文章站
2022-03-16 15:00:45
...
public static function DrawSector(graphics:Graphics,
x:Number=200,
y:Number=200,
r:Number=100,
angle:Number=27,
startFrom:Number=270
):void{
graphics.moveTo(x,y);
angle=(Math.abs(angle)>360)?360:angle;
var n:Number=Math.ceil(Math.abs(angle)/45);
var angleA:Number=angle/n;
angleA=angleA*Math.PI/180;
startFrom=startFrom*Math.PI/180;
graphics.lineTo(x+r*Math.cos(startFrom),y+r*Math.sin(startFrom));
for (var i:int=1; i<=n; i++) {
startFrom+=angleA;
var angleMid:Number=startFrom-angleA/2;
var bx:Number=x+r/Math.cos(angleA/2)*Math.cos(angleMid);
var by:Number=y+r/Math.cos(angleA/2)*Math.sin(angleMid);
var cx:Number=x+r*Math.cos(startFrom);
var cy:Number=y+r*Math.sin(startFrom);
graphics.curveTo(bx,by,cx,cy);
}
if (angle!=360) {
graphics.lineTo(x,y);
}
}