// File: tiltmen.cxx // Written by Michael Main (main@colorado.edu) // This program opens a large, square graphics window and // draws five tilted snowmen of various sizes and locations. // Directives: #include #include #include #include using namespace std; // Named constants: const int S = 500; // Width and height of the graphics window. const int X3 = int(0.93*S); // Prototypes: // This function draws a snowman with the center of the body // at (x,y), the radius of the body given by the 3rd // paramter. The head is at an angle of theta radians from the // center of the body (with 0 radians being to the right), // and the head has a radius that is half that of the body. void draw_snowman(int x, int y, int radius, float theta); // Function definitions: //---------------------------------------------------------- int main( ) { // 1. Initialize the graphics window: initwindow(S, S, "At the north pole!"); // 2. Draw five tilted snowmen: draw_snowman(S/5, S/3, S/17, M_PI/2); delay(1000); draw_snowman(S/5, 2*S/3, S/50, M_PI/4); delay(1000); draw_snowman(X3, int(0.64*S), S/6, -M_PI/2); delay(1000); draw_snowman(int(0.88*S), int(0.12*S), S/73, 3.14159); delay(1000); draw_snowman(int(0.66*S), int(0.1*S), S/39, 0); // 3. Finish: delay(10000); return EXIT_SUCCESS; } //---------------------------------------------------------- //---------------------------------------------------------- void draw_snowman(int x, int y, int radius, float theta) { int hradius = radius/2; int d = radius + hradius; int hx = int(x + d*cos(theta)); int hy = int(y - d*sin(theta)); circle(x, y, radius); // This draws the body circle(hx, hy, hradius); // This draws the head } //----------------------------------------------------------