In this assignment, you will use Pygame
to display line graphs. (Pygame is installed on all of the lab computers in MCReynolds 314.) Installing Pygame on a Mac
with Python 3 is difficult; Mac users should feel free to use Python 2.6 or 2.7 for this and all the Pygame assignments.
You may find strings2points() and splitUp() from Homework 6 to be useful in completing this assignment.
Line Graphs
Your top-level function will be called renderData(). It should take a filename as a parameter:
def renderData(filename):
The filename will correspond to a file generated by the d2file function from Homework 9
You will need to alter the points read in from the file to fit the window
width and height:
The graphics functions expect all points to be lists of tuples. Hence,
when you read in data from the file, it will need to be put in that
form.
Plot each point as a filled-in circle. Also plot a line between each
consecutive pair of points.
At first, just try plotting the points without alteration,
in order to get a sense of what
must be done to make them look right.
If the graph is too small, it will need to be stretched to fit the
viewing window. If it is too large, it will need to be compressed to
fit the viewing window. Hint: Both stretching and
compressing of points can be expressed using the same calculation.
Find the minimum and maximum of each of the x- and y-coordinates, and
employ those values in scaling the points.
Be careful with the y-coordinates; you do not want your graph to be
upside-down.
The program should display the graph until the user closes the window.
Submission
Place all of your code in a single file called hw10.py. Submit via Moodle.