COMP 141: Project 6

Connect the Dots

You will be creating a program that draws pictures according to sequences of (x, y) coordinates read from an input file. This will operate much like a connect-the-dots drawing you may have done as a child.

Read this entire document before beginning the project.

Basic operation of the program

Your program should work like this:

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 that contain a sequence of (x, y) coordinates. The picture is created by drawing lines between pairs of consecutive (x, y) coordinates, following the commands given in the file that describe how the lines should be drawn.

Each line of the file contains exactly one command, of which there are four different types:

As an example, say you are reading the file picture1.txt, which contains the following commands:

canvas 200 300
jumpto 50 50
lineto 90 90
jumpto 50 90
lineto 90 50
jumpto 100 200
lineto 100 250
lineto 150 250
lineto 150 200
lineto 100 200

In order, these commands tell us to:

The final result is that we see the following picture:

You can see how after the canvas command, the following four commands draw the "X" and the last four commands draw the square.

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.

I recommend using set_line_thickness(2) to make the lines a bit thicker and easier to see.

What about dotted lines?

Drawing dotted lines requires a little more work than solid lines because the simplegraphics library does not have a built-in function for drawing a dotted line. To do this, you will define a function called draw_dotted_line that works similarly to the built-in function draw_line. Here's a description of how to do it.

Steps to write the program

  1. Download the cs1graphics.py and simplegraphics.py files from the class website if you need fresh copies of them, and save the files to a folder on your computer that you'll remember.
  2. Create a new Python file called dots_yourLastName_yourFirstName.py in the same folder as the cs1graphics.py and simplegraphics.py files.
  3. Fill in the standard comment header at the top of your program.
  4. Write the draw_dotted_line function as described via the link in the previous section. I recommend writing this all in one file and just commenting out the test cases when you're done.
  5. In your main() function, write code to:

Sample picture files

You should test your program with each of the following files to make sure they draw the pictures correctly. Click on each file to download them.

Sample program interactions

What the user types is in bold. The bracketed comments describe what the program is doing behind the scenes, and are not part of the output.

Run 1:

What file do you want to read? picture1.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 ]

Hints, tips, and questions

Challenges

Submission instructions

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