AS3 画扇形函数。

下面示例中的
DrawSector(moviec,200,200,100,S_angle,270,0xffcc00);
函数就是画扇形的函数,
moviec是扇形所在影片剪辑的名字
第2,3个参数是扇形原点的横纵坐标
第4个参数是扇形的半径
第5个参数S_angle是扇形的角度
第6个参数是扇形的起始角度
第7个参数0xffcc00是扇形的颜色

/*
*Create by Geordi 14th Feb 2008
*function DrawSector is drawing a sector in the flash by actionscript 3 
*/
import flash.display.MovieClip;
import flash.display.Sprite;
var  stag:Sprite = new  Sprite();
addChild(stag);
var  moviec:MovieClip = new  MovieClip;
stag.addChild(moviec);
var  S_angle: int = 60 ;
/*  S_angle is expressed as a number between 0 and 360 degrees. it will draw a 60 
* degree sector in this example, but you could change it to what ever you want 
*/
DrawSector(moviec,
200 , 200 , 100 ,S_angle, 270 , 0xffcc00 );
/*
* mc the movieclip: the container of the sector.
* x,y the center position of the sector
* r the radius of the sector
* angle the angle of the sector
* startFrom the start degree counting point : 270 top, 180 left, 0 right, 90 bottom , 
* it is counting from top in this example. 
* color the fil lin color of the sector
*/
function  DrawSector(mc:MovieClip,x:Number = 200 ,y:Number = 200 ,r:Number = 100 ,angle:Number = 27 ,startFrom:Number = 270 ,color:Number = 0xff0000 ): void  {
    mc.graphics.beginFill(color,
50 );
    
// remove this line to unfill the sector
     /*  the border of the secetor with color 0xff0000 (red) , you could replace it with any color 
    * you want like 0x00ff00(green) or 0x0000ff (blue).
    
*/
    mc.graphics.lineStyle(
0 , 0xff0000 );
    mc.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;
    mc.graphics.lineTo(x + r * Math.cos(startFrom),y + r * Math.sin(startFrom));
    
for  ( var  i = 1 ; i <= n; i ++ ) {
        startFrom
+= angleA;
        
var  angleMid = startFrom - angleA / 2;
         var  bx = x + r / Math.cos(angleA / 2 ) * Math.cos(angleMid);
        
var  by = y + r / Math.cos(angleA / 2 ) * Math.sin(angleMid);
        
var  cx = x + r * Math.cos(startFrom);
        
var  cy = y + r * Math.sin(startFrom);
        mc.graphics.curveTo(bx,by,cx,cy);
    }
    
if  (angle != 360 ) {
        mc.graphics.lineTo(x,y);
    }
    mc.graphics.endFill();
//  if you want a sector without filling color , please remove this line.
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值