WEB开发网      好站好分享!你的一份分享是我们的一份动力;请分享 ---﹥
开发学院图形图像Flash Drawing arcs with AS3 阅读

Drawing arcs with AS3

 2009-10-18 00:00:00 来源:WEB开发网 减小字体增大字体】  关注龙振升的微博
核心提示:If you have ever tried to draw arcs with AS3 (or AS2), you probably smashed your computer on the floor after spending hours with curveTo().That’s not what

If you have ever tried to draw arcs with AS3 (or AS2), you probably smashed your computer on the floor after spending hours with curveTo().

That’s not what we need when we want to draw simple arcs, without any Bezier curve.

That’s why I made my own function.

It’s not that interesting since it only uses a bit of trigonometry, and obviously I did not write it for the sake of writing a function, but at the moment with this script

package {
 import flash.display.Sprite;
 public class arc extends Sprite {
  var my_canvas:Sprite = new Sprite();
  var deg_to_rad=0.0174532925;
  public function arc() {
   addChild(my_canvas);
   my_canvas.graphics.lineStyle(20,0xff0000,1);
   draw_arc(my_canvas,250,200,150,14,180,1);
  }
  public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision) {
   var angle_diff=angle_to-angle_from;
   var steps=Math.round(angle_diff*precision);
   var angle=angle_from;
   var px=center_x+radius*Math.cos(angle*deg_to_rad);
   var py=center_y+radius*Math.sin(angle*deg_to_rad);
   movieclip.graphics.moveTo(px,py);
   for (var i:int=1; i<=steps; i++) {
    angle=angle_from+angle_diff/steps*i;
    movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
   }
  }
 }
}

1 2  下一页

Tags:Drawing arcs with

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接