使用动作脚本如何绘制半圆

时间:2010-07-27 19:12:08

标签: actionscript-3

使用动作脚本如何绘制半圆...我需要在另一个圆圈中添加半圆形圆圈看起来像这样 ![替代文字] [1]

如何在该圆圈内绘制半圆

2 个答案:

答案 0 :(得分:4)

使用以下函数绘制所需的弧。

  function drawArc(centerX, centerY, radius, startAngle, arcAngle, steps){
        startAngle -= .25;
        var twoPI = 2 * Math.PI;
        var angleStep = arcAngle/steps;
        var xx = centerX + Math.cos(startAngle * twoPI) * radius;
        var yy = centerY + Math.sin(startAngle * twoPI) * radius;
        moveTo(xx, yy);
        for(var i=1; i<=steps; i++){
            var angle = startAngle + i * angleStep;
            xx = centerX + Math.cos(angle * twoPI) * radius;
            yy = centerY + Math.sin(angle * twoPI) * radius;
            lineTo(xx, yy);
        }
    }
    lineStyle(0, 0xFF0000);
    drawArc(250, 250, 200, 45/360, -90/360, 20);

半圆?那么加入终点就不是了。使用lineto。

答案 1 :(得分:1)

非常感谢loxxy ..我做了一些改动,也得到了虚线。

function drawArc(centerX,centerY,radius,startAngle,arcAngle,steps){

           centerY=centerY+radius
    startAngle -= .25;
    var twoPI = 2 * Math.PI;
    var angleStep = arcAngle/steps;
          trace(angleStep)
    var xx = centerX + Math.cos(startAngle * twoPI) * radius;
    var yy = centerY + Math.sin(startAngle * twoPI) * radius;
   mc.graphics.moveTo(xx, yy);
    for(var i=1; i<=steps; i++){
        var angle = startAngle + i * angleStep;
        xx = centerX + Math.cos(angle * twoPI) * radius;
        yy = centerY + Math.sin(angle * twoPI) * radius;
        if(i%2==0){
              mc.graphics.moveTo(xx, yy);
        }else{
      mc.graphics.lineTo(xx, yy);
        }
    }
}