< Back

Lab 3: More Turtle and Loops

You have now been briefly introduced to two very powerful constructs in the Python programming language: for loops and functions. Today, we will try to solidify your understanding of these topics, and exploring more of what Turtle lets us do.


Polygons

In a file called Polygons.py, write a program that is able to draw arbitrary polygons to the turtle window. To accomplish this, you should write a function called draw_polygon(x, y, num_sides), which takes an x and y coordinate and the number of sides to draw the shape. It should use turtle to draw the shape in the specified location.

4 sides: 6 sides: 15 sides:

Spirograph

In a file called Spirograph.py, write a program that mimics the Spirograph devices that you likely remember from your childhood. Your program should have a function called draw_spirograph(side_length), which takes 1 integer as a parameter. It should use the information passed to the function to draw a spiral shape with the specified length of a side. Your Spirograph can have as many points as you wish, but it must contain more than 10, and have some circular space in the center that is empty.

Hint

A spirograph can be thought of as just a polygon that allows for it's lines to cross. For example, the star we did last week meets the criteria for a spirograph here.

Play around with amounts of points, and amounts you turn. While not all values will yeild a shape that is closed, you should be able to find one relatively quickly that will.

Your code here will probably look very similar to the star shown in class, and the polygon activity above.