Method to draw an ellipse

Notes:
as this method uses a series of lines to construct the curve, a low angular change will result in a smoother curve. however, if a higher value is used, this will construct what appear to be “warped” polygons. for example, an angular change of 45 degrees (Pi/4 rad) will give an eight sided polygon. changing the dx and dy will still result in an elliptical shape.

ActionScript:

with( MovieClip_Object ) {

	//center of ellipse
	var x0 = Stage.width/2;
	var y0 = Stage.height/2;
	//ellipse bounds
	var dx = 300;
	var dy = 100;
	//angular change
	var dn = 1 * (Math.PI/180);

	var r,x,y;
	lineStyle(1, 0x000000);
	for( var n=0; n<2*Math.PI; n+=dn ) {
		x = dx*Math.cos(n);
		y = dy*Math.sin(n);
		moveTo(x0+x,y0+y);
		x = dx*Math.cos(n+dn);
		y = dy*Math.sin(n+dn);
		lineTo(x0+x,y0+y);
	}

}

Leave a comment

  • Tags

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Archives