• Welcome to Dark Bit Factory & Gravity.
 

How to generate a smooth Circle at runtime?

Started by va!n, January 16, 2008

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

va!n

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

- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

p01

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

Jim

Challenge Trophies Won:

stormbringer

#3
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..
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart