Pixel(Y + vReso/2, X + hReso/2) = texture? texture->Pixel(col[0], col[1]) : col;
An annulus is defined by its center position, together with inner and outer radius. A circle is a special annulus with inner radius of 0.
You can make your draw solid circle (either with texture mapping or not) in Canvas class more general, so this time it draw a general annulus.
void FillAnnulus(int cx, int cy, float r1, float r2, int angularReso, int radianReso);
You need these header files: iostream, sstream and iomanip.ostringstream os; os << setfill('0') << setw(4) << i; canvas.filename = "frame" + os.str() + ".ppm";
You need this to clear the canvas before drawing the next frame.
const int frames = 200; const int radius = 20; const int x0 = -canvas.hReso/2 + radius; const int y0 = -canvas.vReso/2 + radius; int step_x = 5; int step_y = 7; int x = x0, y = y0; for(int i = 0; i<frames; i++) { ostringstream os; os << setfill('0') << setw(4) << i; canvas.filename = "frame" + os.str() + ".ppm"; canvas.Clear(Blue); canvas.SolidCircle(x, y, radius, Magenta); canvas.WritePPM(); // update circle's center: (x, y) x += step_x, y += step_y; if(x + radius >= canvas.hReso/2) // move out of right boundary { x = canvas.hReso / 2 - 1 - 2 * (x+radius - canvas.hReso/2) - radius; // bounce back step_x = - step_x; // will move left } else if(x - radius < -canvas.hReso/2) // move out of left boundary { x = -canvas.hReso/2 + 2 * (-canvas.hReso/2 - (x - radius)) + radius; // bounce back step_x = - step_x; // will move right } if(y + radius >= canvas.vReso/2) // move out of upper boundary { y = canvas.vReso / 2 -1 - 2 * (y+radius - canvas.vReso/2) - radius; // bounce back step_y = - step_y; // will move down } else if(y - radius < -canvas.vReso/2) // move out of bottom boundary { y = -canvas.vReso/2 + 2 * (-canvas.vReso/2 - (y - radius)) + radius; // bounce back step_y = - step_y; // will move up. } }
1.3.6