COMP 141 Fall 2019

Project 6: Connect the Dots

Assigned: Monday, October 21
Due: Tuesday, October 29, 2019 by 11:55pm

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.

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 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 yourLastName_yourFirstName_prg6.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

What to turn in

  • Through Moodle, turn in your code as a file called yourLastName_yourFirstName_prg6.py.
  • Include the standard program header at the top of your Python file.
  • Follow the comment guide to correctly comment your code.
  • Grading

    Your program will be graded on correctness, as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation, and comments (this is not an exhaustive list). See the syllabus for further grading details.

    You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.