Dark Bit Factory & Gravity

ARCHIVE => Archive => GFX & sound => Topic started by: va!n on January 16, 2008

Title: How to generate a smooth Circle at runtime?
Post 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

Title: Re: How to generate a smooth Circle at runtime?
Post by: p01 on January 16, 2008
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
Title: Re: How to generate a smooth Circle at runtime?
Post by: Jim on January 16, 2008
Other possibilities
http://dbfinteractive.com/index.php?topic=2735.0 (http://dbfinteractive.com/index.php?topic=2735.0)

Jim
Title: Re: How to generate a smooth Circle at runtime?
Post by: stormbringer on January 18, 2008
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..