//--------------------------------------------------------- // Lab04 // // Test implementation of worldType class. //--------------------------------------------------------- #include "worldType.h" #include int main() { double x, y; // world coordinates int oldColor; // This application uses two graphics windows. The first is // a default worldType object. worldType w1; // The second graphics window models a world that goes from // -5 to 5 on both axes using a graphics window that is 201 // pixels square whose upper left corner is at (50,100) on // the computer screen. worldType w2(201, 201, 50, 100, -5.0, -5.0, 5.0, 5.0, "Square"); //******************************************* // Do some drawing on world 1 //******************************************* // Draw a grid on world 1 with a spacing of 0.1 between grid lines. w1.setActive(); oldColor = getcolor(); setcolor(RED); x = -1.0; while (x < 1.05) { w1.drawLine(x, -1.0, x, 1.0); x = x + 0.1; } y = -1.0; while (y < 1.05) { w1.drawLine(-1.0, y, 1.0, y); y = y + 0.1; } setcolor(oldColor); // Draw the x-axis and the y-axis. w1.drawLine(0.0, -1.0, 0.0, 1.0); w1.drawLine(-1.0, 0.0, 1.0, 0.0); // Draw a 1.2 x 0.9 rectangle centered on (0.1, -0.2) in the default world. w1.moveTo(-0.5, 0.25); w1.lineTo( 0.7, 0.25); w1.lineTo( 0.7, -0.65); w1.lineTo(-0.5, -0.65); w1.lineTo(-0.5, 0.25); //******************************************* // Now, do some drawing on world 2 //******************************************* // Draw a grid on world 2 with a spacing of 1 between grid lines. w2.setActive(); oldColor = getcolor(); setcolor(RED); x = -5.0; while (x < 5.05) { w2.drawLine(x, -5.0, x, 5.0); x = x + 1.0; } y = -5.0; while (y < 5.05) { w2.drawLine(-5.0, y, 5.0, y); y = y + 1.0; } setcolor(oldColor); // Draw the x-axis and the y-axis. w2.drawLine(0.0, -5.0, 0.0, 5.0); w2.drawLine(-5.0, 0.0, 5.0, 0.0); // Draw a 3.0 x 3.0 square centered at (-2.4, 3.1). w2.setActive(); w2.moveTo(-3.9, 4.6); w2.lineTo(-0.9, 4.6); w2.lineTo(-0.9, 1.6); w2.lineTo(-3.9, 1.6); w2.lineTo(-3.9, 4.6); // Wait for the user to tap a key (with world 2 active). getch(); closegraph(); // Close all graphic windows return 0; }