<math.h> also defines a round() function. If you are including this header file,
should be used to call our version of this function, discussed in earlier lectures.columbia :: round()
void SolidCircle(int center_x, int center_y, int radius, RGB const& col);
and useRGB* operator[] (int r) { assert(r>=0 && r<vReso); return data + r*hReso; }
to access a pixel with the given row and col number. This function is not safe in the sense that an invalid col value is not detected.obj[row][col]
Add a safe pixel access member function to Canvas class.
Pixel() should check both row and col.RGB& Pixel(int row, int col);
After this done, go to your Canvas.cpp, replace any
byobj[row][col]
obj(row, col)
to Canvas class, which will fill the whole canvas to the given color. This is usually used to clear the whole canvas to some background color (ex. Black).void Clear(RGB const& color);
Together we go through the steps needed to generate a animation of a moving circle, bouncing back and forth in a rectangle room. Use IrfanView and UnFREEz to generate the gif animation, and use any browser to show the animation.
So far when we write a pixel with some color, the original color of that pixel is simply overridden by the new color. The other way is to set the pixel with a color which is some kind of interpolation between the new color and the old color. To this end, we can add another data member to RGB class. The data member,
is changed intofloat rgb[3];
or,float rgb[3]; float alpha;
float rgba[4];
The real color is still red, green, and blue componentz; the new component, called alpha component, is only used to determine (in some way) the interpolation(blending) factor.
.new_x = cos(theta) * x - sin(theta) * y; new_y = sin(theta) * x + cos(theta) * y;
1.3.6