Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use this function to draw circle segments (I think I ported it from an online AS2 example on how to draw full circles long ago):</p> <pre><code> /** * Draw a segment of a circle * @param graphics the graphics object to draw into * @param center the center of the circle * @param start start angle (radians) * @param end end angle (radians) * @param r radius of the circle * @param h_ratio horizontal scaling factor * @param v_ratio vertical scaling factor * @param new_drawing if true, uses a moveTo call to start drawing at the start point of the circle; else continues drawing using only lineTo and curveTo * */ public static function drawCircleSegment(graphics:Graphics, center:Point, start:Number, end:Number, r:Number, h_ratio:Number=1, v_ratio:Number=1, new_drawing:Boolean=true):void { var x:Number = center.x; var y:Number = center.y; // first point of the circle segment if(new_drawing) { graphics.moveTo(x+Math.cos(start)*r*h_ratio, y+Math.sin(start)*r*v_ratio); } // draw the circle in segments var segments:uint = 8; var theta:Number = (end-start)/segments; var angle:Number = start; // start drawing at angle ... var ctrlRadius:Number = r/Math.cos(theta/2); // this gets the radius of the control point for (var i:int = 0; i&lt;segments; i++) { // increment the angle angle += theta; var angleMid:Number = angle-(theta/2); // calculate our control point var cx:Number = x+Math.cos(angleMid)*(ctrlRadius*h_ratio); var cy:Number = y+Math.sin(angleMid)*(ctrlRadius*v_ratio); // calculate our end point var px:Number = x+Math.cos(angle)*r*h_ratio; var py:Number = y+Math.sin(angle)*r*v_ratio; // draw the circle segment graphics.curveTo(cx, cy, px, py); } } </code></pre> <p>I think it's close enough to perfect circles. I don't really understand the math inside, but I hope the parameters are clear enough for you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload