The goal of this assignment is to gain experience with functions, loops, and the
turtle module. Do this assignment with your assigned partner.
Download and save a copy of the
my_artwork.py module, which is linked here. Open it in Brackets. Read through the code and see if you can figure out what it will do.
Start a terminal and open a Python interpreter. At the Python prompt, type as follows:
>>> import my_artwork
What do you see?
- Try modifying the program to accomplish the following:
- Make the square into a tall, skinny rectangle.
- Draw a second square inside the rectangle.
- Some of the documentation for the Turtle class is in the textbook. Take a few minutes to skim through the documentation to familiarize yourself with what is there. Then try picking out a few methods that look like they might be interesting, and try them out. Modify your program to use other methods from the book. You can also look up the Turtle documentation online by Googling "python 3.4 Turtle module".
Write a Python program named
drawing.py. Your program should create a Turtle object and use the methods in the book to draw a picture.
Put the code that does this drawing inside a function named
drawpic, so your code can be run in the same way as the code is run in
my_artwork.py. Spend a little bit of time experimenting with the different methods, and then figure out how to combine these methods to draw more complex shapes or pictures.
As you develop your program, try to do the following:
- Use loops to perform repeated tasks.
- Combine simple shapes in more complex ways. For example, combine triangles to form a star, or rectangles to create a tic-tac-toe board, or circles to create an interesting pattern.
- Create functions to draw components of your picture. Use parameters to provide varied inputs to these functions, for example, to draw stars that are different sizes. (The flower-planting programs on page 82 of the textbook are good examples of this.)
- Use variables and arithmetic operations to compute relationships between components of your picture. For example, you might draw a series of circles where each is half the diameter of the previous one.
Optionally use random numbers to make your pictures varied and unpredictable.
Optionally use some advanced features of turtles that you learn from the textbook (appendix B.2) or the online documentation.
Optionally: Use the
time module for animation as follows. Add the line
import time to the top of your program. This gives you access to the
sleep function, which will force Python to wait a certain period of time. For example,
time.sleep(5) will make Python wait 5 seconds.
Be creative, and have fun!