// // Jeff West // CSE143, Summer 2001 // Quiz Section 16 // Circular Weirdness // #include "gp142display.h" #include "gp142.h" #include // Must include this to use the rand() and srand() functions!!! #include // Must include this to use the time() function to seed the random number generator!!! #include // Includes PI constant; cos, sin functions // For many of the GP142 functions, a line width of // zero means to fill the shape being drawn. The // constant FillWidth is used in function calls when a solid // shape is desired. const int FillWidth = 0; // The circle radius -- used in deciding where circle dots can be // placed const double RADIUS = 150.0; const double PI = 3.14159; double randTheta() { // get a random theta -- 2 * PI by 1000.0 then divide the result // by 1000.0 to assist us in getting a theta with three decimal // places of accuracy return (rand() % (int)(2 * PI * 1000.0)) / 1000.0; } void drawRandomCircleDot(GP142Display& display) { // get a random color for the pixel GP142Color color = (GP142Color)(rand() % 24); // get a random theta between 0 and 2 * PI double theta = randTheta(); int x = (int)(RADIUS * cos(theta)); int y = (int)(RADIUS * sin(theta)); display.drawPixel(x, y, color); } //**************************************************************************** // // MAIN // //**************************************************************************** // * Main program contents: // * - Major program variables that persist throughout execution // * - Event loop that processes GP142 events, // * and updates variables and redraws the window as needed. until the user quits // int main() { srand( (unsigned)time( NULL ) ); // Event handling and menu items: bool quit = false; // = "user has selected quit" char key_pressed; // last keyboard character from key event int mouse_x, mouse_y; // x and y coordinates of latest mouse event GP142Display display; // our GP142 window display.clear (White); display.setAnimation (Run); // * Main event loop: // * ---- ----- ----- // * Wait for the next user action, decode it, and call an // * appropriate function to handle it. Repeat until the // * user selects quit. // while (!quit) { display.getNextEvent(mouse_x, mouse_y, key_pressed); // The code for redrawing the screen goes here... drawRandomCircleDot(display); } return 0; }