CSCI 261 - Programming Concepts (C++)

Fall 2016 - Assignment 09 - Turtle Graphics

Quick Links: Blackboard | EECS | Mines | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This assignment is due by November 02, 2016 08:00am.


Concepts



In this assignment, we will continue to practice file I/O, data manipulation, loops, and drawing with SFML. For this specific assignment you should download the SFML project template that has initial code and other resource files for you to get started. See Lab08B for details on setting up the project template.

The first thing you should note is that you have two weeks to complete this assignment. A couple of notes on the assignment:
  • This assignment will be a little more involved so get started right away.
  • This assignment will use techniques from the next two weeks of labs.
  • You can get started on the assignment right away as we have structured the assignment to be done in two parts if you so wish.
  • If you choose to follow our suggested timeline, you may submit your current code at the "Week08" point - October 26 08:00am - to receive 2 points extra credit. The graders will then give you feedback on your current code.


Overview



The ultimate goal of this assignment is to plot the points generated by our Turtle from the original Lab06B. The labs over the next two weeks will give us all the pieces to accomplish this task. The task can be broken into two parts. The first part will be drawing lines based on user input. The second part will then be using file input instead of user input.


Step I: The Specifics



As stated above, we'll be using SFML so we'll want to start with the SFML project template. Lab08A showed us how to have the user enter an arbitrary number of values. Use your Point struct from Lab06A and create a vector of Points. First ask the user how many points they would like to enter. Now have the user enter that many X and Y values to push Points onto our vector. Your program should do the following at this point:

How many points do you want to enter? 3
Enter Point 1 X: 150
Enter Point 1 Y: 200
Enter Point 2 X: 400
Enter Point 2 Y: 350
Enter Point 3 X: 250
Enter Point 3 Y: 500

The next step is to now plot these points using SFML by connecting each successive pair of points with a line. That is to say, we want to connect Point 1 and Point 2. We also want to connect Point 2 and Point 3. This will continue with Points 3 & 4, 4 & 5, etc. for as many points as we have. Lastly, we want to connect our last point back to our first point. The following websites have some information on how and why to draw lines: Drawings Shapes With SFML and Vertex Arrays. You should read the documentation to fully understand what is going on, but to tease out the relevant parts we need to do the following steps in our draw loop:

sf::Vertex line[2] = 
{
    sf::Vertex( sf::Vector2f( 10, 10 ) ),
    sf::Vertex( sf::Vector2f( 150, 150 ) )
};

window.draw( line, 2, sf::Lines );

The first step is creating an array of type sf::Vertex that is of size 2. sf::Vertex is an SFML class that we have access to and it contains information about a vertex we wish to draw to the screen. The next step is to initialize our array. We will need to specify two vertices for our array. To specify a vertex, we need to provide the X, Y location of the vertex as an sf::Vector2f. Once we have specified the X, Y location of our two vertices, we then tell the window to draw our array of 2 vertices using a Line. This line will connect the points (10, 10) and (150, 150). You will need to follow the exact format as written above to draw a line to the SFML window.

We will need to do the above steps for every successive pair of points in our vector entered by the user. Hmm, this sounds like a job for a loop! Your program should now create a window like the one below:
SFML Triangle
At this point, you should have a program that prompts the user to enter some number of points. These points are then plotted to an SFML window. You now have the option to submit your partially completed solution to Blackboard to receive feedback from the graders. Your solution does not need to be fully working, but should be working towards a solution. To receive extra credit, submit your code at this point to Blackboard under Week08 by Wednesday, October 26 at 08:00 am. The graders will provide you with feedback by Saturday 08:00 am. There is no late deadline to receive the extra credit. In order to receive the extra credit and feedback, your Week08 submission must be submitted on time.


Step II: The Specifics



The next step is to take the user out of the loop. We are going to use the output file from Lab09A to load our points from. We no longer want to use cin to ask the user to enter all the values. Prompt the user to enter the name of the file that contains the data generated by Lab09A. Then, create an ifstream that will open the file generated by Lab09A. Wow! The format of the data in the file matches exactly what the user was entering from the steps above. That makes it super easy to swap out the user input for the file input. Now your program will look like the following when run:

Enter the name of the file to open: circle_6.txt
Loading points from file "circle_6.txt"...
...loading 6 points from file...
...loading point (1.500, 0.866) from file...
...loading point (1.000, 1.732) from file...
...loading point (0.000, 1.732) from file...
...loading point (-0.500, 0.866) from file...
...loading point (0.000, 0.000) from file...
...loading point (1.000, 0.000) from file...
...finished loading points! 

The rest of your program should now run seamlessly and plot these new points. However, the points range in value between -1 and 2. Plotting these points will make a very small shape in the corner of our window. Before we draw each point, we will need to scale and shift each point. Our window has a size of (width x height), so we want our shape to lie roughly in the middle of our window. We'll also make the shape larger. Use the following equations to modify each X, Y component of our Point.

Point manipulation

Now when we plot these modified points, we should have the following output in our SFML Window:
SFML Hexagon
If we run Lab09A with a higher resolution, then we can see that we have a better approximation for a circle. Running with a resolution of 25 generates the following output:
SFML Circle
If you are having trouble with Lab09A and unable to generate a file at this point, you can use these two sample files which were used to generate the above images: a09_input_6.txt & a09_input_25.txt.


Functional Requirements



  • Your program will be tested against inputs other than 6 and 25. Your solution must not have hard coded values for the number of points to remain flexible and accept any file as input.


Grading Rubric


Your final submission will be graded according to the following rubric.

PercentageRequirement Description
10%Labs completed
80%Circle approximation is drawn to screen using SFML
10%(1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed (5) Assignment compiles
+5%Extra Credit 1: Week08 Progress Check submitted
+5%Extra Credit 2: Lab08B is animated


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

In summary, for homework due on Wednesday, November 02 follow these specific steps:
  • create a directory called week09.
  • within week09, create five subdirectories: Lab08A, Lab08B, Lab09A, Lab09B and A09.
  • within your new week09/Lab08A directory, copy in your main.cpp file and any other files you created (*.h, *.cpp) from your Lab08A solution.
  • within your new week09/Lab08B directory, copy in your main.cpp file and any other files you created (*.h, *.cpp) from your Lab08B solution.
  • within your new week09/Lab09A directory, copy in your main.cpp file and any other files you created (*.h, *.cpp) from your Lab09A solution.
  • within your new week09/Lab09B directory, copy in your main.cpp file and any other files you created (*.h, *.cpp) from your Lab09B solution.
  • within your new week09/A09 directory, copy in your main.cpp file and any other files you created (*.h, *.cpp) from your A09 solution.
  • compress the week09 directory (see Step 3 here for details).
  • submit the week09.zip file to Blackboard (see Steps 5-10 here for details).
  • after you submit, download the file and double check it contains all that you think it contains!

This assignment is due by November 02, 2016 08:00am.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0