[A89] Re: filling ellipses


[Prev][Next][Index][Thread]

[A89] Re: filling ellipses




I have taken algebra and all sorts of stuff so I know that formula.  The problem is implementing
it.

> > The equation (((x-h)^2)/a^2) + (((y-k)^2)/b^2) = test

Olle:
Thanks for the link-I copied the code, changed them to DrawPix, chose 20,20 for a,b then wrote in
40,40 as the center.  The result was somewhat strange, though.  If you'd like a screenshot, go to
www.geocities.com/jefromi42/ellipse.bmp

jeff

Here's the code i used if you want to try it:

void symmetry(int x,int y)
{
 DrawPix(40+x,40+y,A_NORMAL);  
 DrawPix(40-x,40+y,A_NORMAL);  
 DrawPix(40-x,40-y,A_NORMAL);
 DrawPix(40+x,40-y,A_NORMAL);
}

void bresenham_ellipse(int a, int b)
{
 int x,y,a2,b2, S, T;

 a2 = a*a;
 b2 = b*b;
 x = 0;
 y = b;
 S = a2*(1-2*b) + 2*b2;
 T = b2 - 2*a2*(2*b-1);
 symmetry(x,y);
 do
   {
    if (S<0)
       {
        S += 2*b2*(2*x+3);
        T += 4*b2*(x+1);
        x++;
       }
      else if (T<0)
          {
           S += 2*b2*(2*x+3) - 4*a2*(y-1);
           T += 4*b2*(x+1) - 2*a2*(2*y-3);
           x++;
           y--;
          }
         else
          {
           S -= 4*a2*(y-1);
           T -= 2*a2*(2*y-3);
           y--;
          }
    symmetry(x,y);
   }
 while (y>0);
}


void _main(void)
{
	ClrScr();
	bresenham_ellipse(20,20);
	ngetchx();
}

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



References: