Browse Source

* libee/conic.c:

+ ee_draw_ellipse().


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@132 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 years ago
parent
commit
bd7633083f
2 changed files with 51 additions and 0 deletions
  1. +50
    -0
      libee/conic.c
  2. +1
    -0
      libee/ee.h

+ 50
- 0
libee/conic.c View File

@@ -47,3 +47,53 @@ void ee_draw_circle(int x, int y, int r, char c)
}
}

static void ellipsepoints(int xo, int yo, int x, int y, char c)
{
ee_putcharTO(xo + x, yo + y, c);
ee_putcharTO(xo - x, yo + y, c);
ee_putcharTO(xo + x, yo - y, c);
ee_putcharTO(xo - x, yo - y, c);
}

void ee_draw_ellipse(int xo, int yo, int a, int b, char c)
{
int d2;
int x = 0;
int y = b;
int d1 = b*b - (a*a*b) + (a*a/4);

ellipsepoints(xo, yo, x, y, c);

while( a*a*y - a*a/2 > b*b*(x+1))
{
if(d1 < 0)
{
d1 += b*b*(2*x+1); /* XXX: "Computer Graphics" has + 3 here. */
}
else
{
d1 += b*b*(2*x*1) + a*a*(-2*y+2);
y--;
}
x++;
ellipsepoints(xo, yo, x, y, c);
}

d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
while(y > 0)
{
if(d2 < 0)
{
d2 += b*b*(2*x+2) + a*a*(-2*y+3);
x++;
}
else
{
d2 += a*a*(-2*y+3);
}

y--;
ellipsepoints(xo, yo, x, y, c);
}
}


+ 1
- 0
libee/ee.h View File

@@ -81,6 +81,7 @@ char ee_get_key(void);
void ee_draw_line(int, int, int, int, char);
void ee_draw_thin_line(int, int, int, int);
void ee_draw_circle(int, int, int, char);
void ee_draw_ellipse(int, int, int, int, char);
void ee_fill_triangle(int, int, int, int, int, int, char);

int ee_rand(int, int);


Loading…
Cancel
Save