3 Replies Latest reply on Jan 13, 2009 10:06 AM by kglad

# Draw ellipse

I have found a script to draw a ellipse, but I cant get to work. I have made a few changes so it's easy to paste in but nothing that should influence the funcion!?

It just draws a straight line. (the diagonal I think?)

I found the script here:
http://e-articles.info/e/a/title/Drawing-an-Ellipse-using-ActionScript/

- and here is my version with a few moderations:

{
var angleDelta = Math.PI / 4;

var rx, ry, ax, ay;
for (var i = 0; i < 8; i++)
{
angle += angleDelta;
rx = x + Math.cos(angle-(angleDelta/2))*(xCtrlDist);
ry = y + Math.sin(angle-(angleDelta/2))*(yCtrlDist);
mc.curveTo(rx, ry, ax, ay);
}
}

var tst = _root.createEmptyMovieClip("ellipse", 1);
tst.lineStyle(1, 0x000000, 100);
drawEllipse(tst, 100, 200, 300, 300);
try:

• ###### 2. Re: Draw ellipse
it works, but I think the lineTo() is a bit "distorted" compared to curveTo()

{
var smoothness:Number = 360;
var twoPI:Number = Math.PI*2/smoothness;
for(var t=0;t<=smoothness;t++)
{
ang = t*twoPI;
}
}

var tst = _root.createEmptyMovieClip("ellipse", 1);
tst.lineStyle(1,0x0000FF,100);
drawEllipse(tst,100,100,120,120);

MovieClip.prototype.drawCircle = function(center, rad, fillColor, fillAlpha, lineColor, lineAlpha, lineWidth)
{
if (!fillColor) {
// if fillColor is not specified black is assigned @ alpha 100%
fillColor = 0x000000;
fillAlpha = 100;
}
if (lineColor) {
// if lineColor is specified a line is drawn, if not not
// if lineWidth is not specified width is set @ 1 pixel
// if lineAlpha is not specified alpha is set @ 100%
lineStyle(lineWidth+1*(lineWidth == undefined), lineColor, lineAlpha+100*(lineAlpha == undefined));
}
beginFill(fillColor, fillAlpha);