Project 2: A Shape Collection
Summary: In this project I created shapelib.py, which has functions that draw various shapes based on parameters,
as well as main.py, which has the main code and two functions that use shapes from shapelib to create landscapes.
Over the course of this project, the shapes I created became more advanced; initially, I created basic shapes, such
as triangles, and eventually I used these shapes to create aggregate shapes, like trees and leaves. After creating
these shapes, I used them to create two Maine landscapes, one in the fall and the other in winter.
Description of Files:
This file contains three basic shape functions (block, triangle, and octagon), two aggregate shape functions (tree
and leaf), and a goto() function that moves the turtle's cursor to a specified location without drawing anything. For the
basic shapes, I used the turtle's forward and left functions inside of for loops to create them. The block function
draws a block with a specified width and height, and the triangle and octagon functions create their respective shapes
based on the specified side length. All three basic shape functions have parameters that control the shape's location,
size, and color.
The following image is from my testing of the triangle and octagon shape functions:
The first aggregate shape function I created was tree, which uses the block function to draw a trunk,
followed by a for loop that creates three green triangles on top of the trunk. The second aggregate shape function is
leaf, which creates a leaf that is the shape of a stretched octagon with a small stem attached to it. This function uses
two octagons and one block to create the leaf, and allows for the user to specify the leaf's color. Both the tree and
leaf functions have parameters that control their location and scale.
The following image shows my testing of the leaf and tree shape functions:
This file contains two functions, outdoors1 and outdoors2, that create different Maine landscapes using the shapes
from shapelib.py, as well as the main code for the program. The outdoors1 function draws a fall landscape in Maine
with blue skies, the sun, a pine forest, and fallen leaves on the ground. 300 leaves are drawn on the ground by
using a for loop; these leaves are all randomly oriented and located (using the random import), and are either
orange, yellow, or red (if/else statements decide the colors; there are an equal number of each color leaf). After the
leaves are drawn, this function uses a for loop to draw 100 trees of various sizes at random X coordinates on the
plane Y=10. Again, the random function is used to create variations in the size and location of these trees.
Here is an image showing an output from the outdoors1 function:
The outdoors2 function draws a winter landscape in Maine with gray skies, snow covered ground, a large pine forest,
and mountains in the background. The ground and sky are drawn using the block function from shapelib.py, and
the mountains are drawn with a for loop that draws 50 mountains randomly sized and that are randomly distributed
throughout the backdrop of the drawing (by use of the random import). After drawing the mountains, this function
draws a forest of 100 trees in the lower part of the window using a for loop and parameters that make sure the trees
are correctly layered relative to the landscape. These trees are sized and located based on functions from the random
Here is an output from outdoors2:
Extensions: I incorporated for loops in both files I created and used functions from the random import in my main.py
file. See the file descriptions above for more detail.
What I Learned: In this project I learned a lot about the random import in Python and its functions, and continued
to learn about syntax in Python and debugging. This project also taught me additional functions from the turtle import
that I had not used before, such as the fill functions.
python.org (to look up functions for the random and turtle classes)