COMP 141: Project 6

Connect the Dots

You will be creating a program that draws pictures according to sequences of coordinates read from an input file.

What you need to do

Write a program that does the following: Your program will not receive full credit if there are any error messages printed in your output, even if the picture is drawn correctly.

You should follow the guidelines for commenting your code set forth in earlier projects.

The picture file format

The picture files your program will process are regular text files. Each file is organized into "shapes," where each shape is a list of (x, y) coordinates where line segments should be drawn between consecutive pairs of coordinates. Each shape ends with the coordinates (-1, -1), which is not part of the shape and is only used in the file to signal the end of the shape.

For instance, say you have the file "shapes.txt" that looks like this:

50 50
50 100
100 50
50 50
-1 -1
100 100
150 150
150 100
-1 -1
Notice that there are two lines with "-1 -1" which means there are two shapes in the file. The first shape is bounded by the coordinates (50, 50), (50, 100), (100, 50), and (50, 50), in other words, lines 1-4 in the file. The second shape is bounded by the coordinates (100, 100), (150, 150), and (150, 100), or lines 6, 7, and 8 in the file.

These shapes would be drawn as shown below. Notice how whenever -1 -1 is reached, the current shape is ended (not necessarily at the same point it began) and a new shape may begin. Every shape ends with -1 -1.

How to draw the shapes

You do not need to draw an entire shape at once. By reading the file line-by-line and using the sliding window technique, you should be able to draw lines between the "previous point" and the "current point" by using draw_line from the simplegraphics library.

Sample interaction

What the program prints is in bold, what the user types is in italics, and brackets describe what the program is doing.

Run 1:

What file do you want to read? shapes.txt
[ program opens window and draws picture ]
Click the canvas to close the window and end the program.
[ user clicks the canvas and the program ends ]
Run 2:
What file do you want to read? homer.txt
[ program opens window and draws picture ]
Click the canvas to close the window and end the program.
[ user clicks the canvas and the program ends ]
You should test your program with shapes.txt (corresponding picture), two-triangles.txt (corresponding picture), stars.txt (corresponding picture), panda.txt (corresponding picture), and homer.txt (corresponding picture). The picture files are also available in my public folder.

Hints

Challenges

What to turn in

Through Moodle, turn in your code as a file called dots_yourLastName_yourFirstName.py.