Author Topic: How to generate a smooth Circle at runtime?  (Read 3483 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
How to generate a smooth Circle at runtime?
« 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

- 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:

Offline p01

  • Atari ST
  • ***
  • Posts: 158
  • Karma: 51
    • View Profile
    • www.p01.org
Re: How to generate a smooth Circle at runtime?
« Reply #1 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

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: How to generate a smooth Circle at runtime?
« Reply #3 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..
« Last Edit: January 18, 2008 by stormbringer »
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