libmonochrome/src/ML_filled_ellipse.c

54 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ML_filled_ellipse.c */
/* | Project : monochromelib */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_filled_ellipse(int x, int y, int radius1, int radius2, ML_Color color)
{
int plot_x, plot_y;
float d1, d2;
if(radius1 < 1 || radius2 < 1) return;
plot_x = 0;
plot_y = radius2;
d1 = radius2*radius2 - radius1*radius1*radius2 + radius1*radius1/4;
while(radius1*radius1*(plot_y-.5) > radius2*radius2*(plot_x+1))
{
if(d1 < 0)
{
d1 += radius2*radius2*(2*plot_x+3);
plot_x++;
} else {
d1 += radius2*radius2*(2*plot_x+3) + radius1*radius1*(-2*plot_y+2);
ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color);
ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color);
plot_x++;
plot_y--;
}
}
ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color);
ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color);
d2 = radius2*radius2*(plot_x+.5)*(plot_x+.5) + radius1*radius1*(plot_y-1)*(plot_y-1) - radius1*radius1*radius2*radius2;
while(plot_y > 0)
{
if(d2 < 0)
{
d2 += radius2*radius2*(2*plot_x+2) + radius1*radius1*(-2*plot_y+3);
plot_y--;
plot_x++;
} else {
d2 += radius1*radius1*(-2*plot_y+3);
plot_y--;
}
ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color);
if(plot_y > 0)
ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color);
}
}