2010-07-27 90 views

回答

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

非常感謝你loxxy ..我做了一些改動,也得到了虛線。

功能drawArc(的centerX,centerY,半徑,由startAngle,arcAngle,步驟){

  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); 
     } 
    } 
}