I have a function in C++ which draws an ellipse. Now I want to add a fill option to that ellipse. How do I do that? I tried using the flood fill algorithm, but it does not work correctly when the surface already contains paintings.
Here is my current algorithm:
const double TwoPI = ( PI * 2 );
const double Step = ( PI / 180.0f );
for( double i = 0; i < TwoPI; i += Step )
{
float x_offset = ( radiusX * cos( (float) i ) );
float y_offset = ( radiusY * sin( (float) i ) );
int x = int( a_X + x_offset );
int y = int( a_Y + y_offset );
if( prevX == -1 && prevY == -1 )
Plot( x, y, color );
else
Line( prevX, prevY, x, y, color );
}
Well, one idea could be to just traverse half the circle, and instead compute points that are symmetrically placed around ie the y axis. Then draw a horizontal line between them, filling in all the pixels.
You travel in both directions and drow a line from edge to edge Something like this: I did not try to run it.It's just the idea.Its supposed to paint a filled circle.
const double TwoPI = ( PI * 2 );
const double Step = ( PI / 180.0f );
double start=0;
for( double i = 0; i < TwoPI; i += Step )
{
float x_offset = ( radiusX * cos( (float)start+ i ) );
float y_offset = ( radiusY * sin( (float) start+i ) );
float x2_offset = ( radiusX * cos( (float)start - i ) );
int x = int( a_X + x_offset );
int x2 = int( a_X + x_offset );
int y = int( a_Y + y_offset );
Line( x, y, x2, y, color );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.