Handouts: Graphics Reference

By repeatedly drawing lines, we can make a curved looking shape. Consider the example below where we imagine dots evenly space along the bottom and the left of a canvas. If we connect the topmost dot on the left edge to the left most dot on the bottom edge, we would be a line like the picture of the far left. If we then connect the next 9 dots we get a picture in the middle and if we connect all dots we get the picture on the right.

Write a program that creates the "curve" in the above right image using straight lines.

Hints and Tips

  • Remember that you can use the loop variable of a for loop:

    for i in range(NUM_LINES):
        ... some code that uses i here to draw lines...

    This program can be completed with a single for loop by using the loop variable, i. Do you see how? (Hint: We know that the topmost dot on the left edge can only connect to the leftmost dot on the bottom edge. Let's suppose this is the line we draw when i = 0. What about for when i = 1? The second dot from the top on the left edge can only connect to one specific dot on the bottom edge! And so on...)

  • Check out the Graphics Reference (click on "Show/Hide Quick Reference") for tips on how to draw lines onto the canvas.

  • Use a pencil and paper to sketch out your idea! Even though we're coding using the computer, sometimes it's useful to first draw what you think is happening, and then write out the code.