Dark Bit Factory & Gravity
ARCHIVE => Archive => GFX & sound => Topic started by: va!n on January 16, 2008
-
yes its me again....
i lost an old but nice source (from the web) to draw smooth circles... has someone such a psydo basic source to draw
filled and non-filled circles smooth? (without blurring, because afaik blurring looks not so nice)
DrawCricleA( x, y, w, h, Color) ; filled
DrawCirlceB( x, y, InnerRadius, OuterRadius, Color) ; non filled
-
what do you mean by smooth ? with AA ?
Any Bresenham-y approach would do. You can walk along the circle(s) and check whether the squared distance of the new x,y position exit the circle, if it does, go the other way ( down instead of left ), and use vertical and horizontal mirroring. I could cook up something quick, after work, in JS if you want
-
Other possibilities
http://dbfinteractive.com/index.php?topic=2735.0 (http://dbfinteractive.com/index.php?topic=2735.0)
Jim
-
Do you mean anti-aliased circles? If you do not understand the Bresenham's algorithm, you can start with a simple test beased on the radius. Scan all the pixels in the circle area and test distance to center:
for (y=0; y < diameter; y++)
{
for (x=0; x < diameter; x++)
{
d = distance (x,y,centerX,centerY)
if (d < radius)
{
putPixel(x,y);
}
}
}
to add antialiasing: if (d < radius) then putPixel(x,y,value)
if (d >= radius) && (d < (radius+1.0))
{
aaValue=1.0-(d-radius);
putPixel(x,y,aaValue);
}
But as Jim said, an anti-aliased, Bresenham-based algorithm would be much more efficient..