// Copyright 2000 // College of Computer Science // Northeastern University Boston MA 02115 // This software may be used for educational purposes as long as this copyright // notice is retained at the top of all files // Should this software be modified, the words "Modified from Original" must be // included as a comment below this notice // All publication rights are retained. This software or its documentation may // not be published in any media either in whole or in part. /////////////////////////////////////////////////////////////////////////////// // MorphProject.cpp // // Program that paints and morphs a polygonal drawing // With thanks and credits for the project idea to: // Harriet Fell and Erich Neuwirth /////////////////////////////////////////////////////////////////////////////// // The standard include files that include traditional C and C++ headers and // many other Core Tools headers ... see CHeaders.h for additional details #include "IOTools.h" #include "Graphics.h" #include "Random.h" #include "FileTool.h" #include "Delay.h" // Enter project specific include files here as well as classes and functions // that you choose to define in the main shell rather than in separate files // use run and step to define the animation mode enum{ step = false, run = true }; // Define class Morph with the following member functions: // // default constructor, // Set function // constructor that calls Set // Interpolate member function // Animate member function // // and private functions Adjust and InBetween // class Morph{ // ************ Enter your code here ************* }; // end of class Morph // Display the start image in GraphicsWindow(0) // Display the stop image in the GraphicsWindow(2) // Repeat: // prompt the user for interpolation factor // generate the morphed image // displays the morphed image in GraphicsWindow(1) // void InterpolateLoop(Morph& Test){ double x; // interpolation factor PolygonWidget PW; // PolygonWidget for drawing // draw the start image ClearDrawing(0); PW.Set(Test.Interpolate(0)).Draw(0); // ************ Enter your code here ************* }; // end of InterpolateLoop function // Select and open a file // Read polygon data from the file into a given PolygonData object // Return the size of the new polygon // int ReadingPolygon(PolygonData& Poly){ // ************ Enter your code here ************* }; // end of ReadingPolygon(PolygonData& Poly) // Print the list of available tests // Prompt the user to choose a test // // Return the selected test number in a reference argument n // Return false if no test is selected // bool SelectTest(int& n){ cout << "Tests available:" << endl << endl; cout << "1. Fixed input, same size, single step" << endl; cout << "2. Fixed input, different size, single step" << endl; cout << "3. Fixed input, same size, animated" << endl; cout << "4. Fixed input, different size, animated" << endl; cout << "5. File input, single step or animated" << endl << endl; cout << "Hit RETURN to end the program" << endl << endl;; if (ReadingInt("Type in the number of the test to run:", n)){ if (n < 0) // no such test -> set to 1 n = 1; else if (n > 5) // no such test -> set to 5 n = 5; return true; // valid test selected } else return false; // no test selected }; // end of SelectTest function // ****** THE FIVE TEST OPTIONS ****************************** void Test1(){ cout << "Test 1: Fixed input, same size, single step" << endl; PolygonData First; PolygonData Last; // hexagon First.Append(150, 60); First.Append(240, 100); First.Append(240, 200); First.Append(150, 240); First.Append( 60, 200); First.Append( 60, 100); First.Append(150, 60); // tristar Last.Append(150, 140); Last.Append(240, 100); Last.Append(160, 160); Last.Append(150, 240); Last.Append(140, 160); Last.Append( 60, 100); Last.Append(150, 140); Morph Test(Last, First); InterpolateLoop(Test); }; // end Test1() void Test2(){ cout << "Test 2: Fixed input, different size, single step" << endl; PolygonData First; PolygonData Last; // hexagon First.Append(150, 60); First.Append(240, 100); First.Append(240, 200); First.Append(150, 240); First.Append( 60, 200); First.Append( 60, 100); First.Append(150, 60); // square Last.Append(100, 100); Last.Append(200, 100); Last.Append(200, 200); Last.Append(100, 200); Last.Append(100, 100); Morph Test(Last, First); InterpolateLoop(Test); }; // end Test2() void Test3(){ cout << "Test 3: Fixed input, same size, animate" << endl; PolygonData First; PolygonData Last; int steps; // hexagon First.Append(150, 60); First.Append(240, 100); First.Append(240, 200); First.Append(150, 240); First.Append( 60, 200); First.Append( 60, 100); First.Append(150, 60); // tristar Last.Append(150, 140); Last.Append(240, 100); Last.Append(160, 160); Last.Append(150, 240); Last.Append(140, 160); Last.Append( 60, 100); Last.Append(150, 140); Morph Test(Last, First); //Test.Set(Last, First); steps = RequestInt("Number of steps:",10); bool mode = Confirm("Run through?", run); Test.Animate(steps, mode); }; // end Test3() void Test4(){ cout << "Test 4: Fixed input, same size, animate" << endl; PolygonData First; PolygonData Last; int steps; // hexagon First.Append(150, 60); First.Append(240, 100); First.Append(240, 200); First.Append(150, 240); First.Append( 60, 200); First.Append( 60, 100); First.Append(150, 60); // square Last.Append(100, 100); Last.Append(200, 100); Last.Append(200, 200); Last.Append(100, 200); Last.Append(100, 100); Morph Test(Last, First); //Test.Set(Last, First); steps = RequestInt("Number of steps:",10); bool mode = Confirm("Run through?", run); Test.Animate(steps, mode); }; // end Test4() void Test5(){ cout << "Test 5: File input, single step or animated" << endl; PolygonData First; PolygonData Last; Morph Test; ClearDrawing(0); ClearDrawing(1); ClearDrawing(2); // read polygon data from two files if ((ReadingPolygon(First)) && (ReadingPolygon(Last))){ Test.Set(First, Last); do { if (Confirm("Animate (Y) or Interpolate(N)?", true)){ // animation: select number of steps int s = RequestInt("Number of steps:", 10); // select run or step mode bool mode = Confirm("Run through?", run); Test.Animate(s, mode); } else { // interpolation: InterpolateLoop(Test); } // repeat if you wish with more speed, fewer steps, ... } while (Confirm("One more time?", true)); } }; // end of Test5() int main(int argc, char* argv[]) { // Build graphics window 0 for the original picture GraphicsWindow GW0(300, 300); // Build graphics window 1 for the morphed picture GraphicsWindow GW1(300, 300); GW1.PlaceRight(0); // Build graphics window 2 for the final picture GraphicsWindow GW2(300, 300); GW2.PlaceRight(1); // Move the console below graphics window 0 ConsolePlaceBelow(0); // Give the console the focus for user interaction MakeConsoleForeground(); ////////// // Enter the main program here int n; while (SelectTest(n)){ switch (n){ case 1: // Fixed input, same size, single step Test1(); break; case 2: // Fixed input, different size, single step Test2(); break; case 3: // Fixed input, same size, animated Test3(); break; case 4: // Fixed input, different size, animated Test4(); break; case 5: // File input, single step or animated Test5(); }; }; // end of while - end of program ////////// // The lines below make sure that the graphics windows remain open just // before the program terminates PressReturn("\nThe main program is about to terminate\n"); return 0; }