I can't seem to make a perfect circle with curveTo() in Flash...
If you know the solution please tell.
If you don't know what I'm talking about I've attached an FLA w/ the problem.
-Thanks
Printable View
I can't seem to make a perfect circle with curveTo() in Flash...
If you know the solution please tell.
If you don't know what I'm talking about I've attached an FLA w/ the problem.
-Thanks
When drawing circles, it helps to use sin/cos to find the points.
8 arcs is sufficient to make a pretty good one. Here's a sample.
I'm using a modified version of this function a few threads down to make a worm out of fake spheres - check it out.
code:
kRadiansToDegrees = 180/Math.PI;
kDegreesToRadians = Math.PI/180;
MovieClip.prototype.drawCircle = function(x,y,radius)
{
var r = radius;
var n= 8;
var theta = 45*kDegreesToRadians;
var cr = radius/Math.cos(theta/2);
var angle = 0;
var cangle = -theta/2;
this.moveTo(x+r, y);
for (var i=0;i < n;i++)
{
angle += theta;
cangle += theta;
var endX = r*Math.cos (angle);
var endY = r*Math.sin (angle);
var cX = cr*Math.cos (cangle);
var cY = cr*Math.sin (cangle);
this.curveTo(x+cX,y+cY, x+endX,y+endY);
}
}
// sample usage
_root.lineStyle(2,0,100);
_root.drawCircle(100,100,50);
For help in understanding how sin/cos are used, check out the first page of posts in the Physics forum...
Circles (and radial symmetry) are one of my personal obsessions. You will find lots of movies featuring circles on my website, link below.
EDIT: Removed vestigal code, per discussion below.
Where is variable bA (var angle = bA*kDegreesToRadians) defined?
Whoops sorry, this version was modified from one I wrote which drew partial circles (arcs), using beginning angle (bA) and end angle (eA) as arguments to the function.
You can replace that line with:
var angle = 0;
and it will still work. If you want the one that draws partial circles (or the one that draws ovals) let me know.
Got it, thanks :D