You will start with the program below and modify it.
Don't create multiple trinkets/projects, but rather keep evolving the same program/project.
The program on the right uses a turtle to draw a square.
1. Remix and modify the program to draw a shape with as many sides as are associated with your name in the list of ePortfolio pages.
For example:
The process of encapsulation is "bundling together" parts of a program (or commands) into functions.
Modify your program above.
2. Encapsulate your program into a function named appropriately (e.g. triangle, pentagon, hexagon, etc.) - see polygon names
The process of generalization is making your functions more flexible so they can handle or do more than one fixed thing.
Modify your program above.
3. Generalize your polygon drawing function, so it gets the length of the side of the polygon and draws the appropriately-sized shape associated with your name.
4. Create another function named
poly(t, length, n) which takes 3 parameters: a turtle, a side length, and the number of sides, and draws the appropriate n-sided polygon.
5. Using poly() you can draw a circle. Create a new function named circle() which in turn uses poly() to drawing a circle with a specified diameter.
Use poly() with n = 36, i.e., it uses a 36-sided polygon.
Using poly() with a certain length parameter, it is not immediately obvious what the diameter of the circle will be.
6.
Modify your program above so that your encapsulation (function) replaces the previous code.
For example:
def init(t):
... # initializes turtle t
def square(t):
... # uses turtle t to draw a square, of size of your choosing
abbie = turtle.Turtle()
init(abbie)
square(abbie)
For example:
def square(t, length):
... # uses turtle t to draw a square, with a side equal to length
side = 100
abbie = turtle.Turtle()
init(abbie)
square(abbie, side)
For example:
def poly(t, length, n):
...
side = 30
amy = turtle.Turtle()
n_sides = 12
poly(amy, side, n_sides)
For example:
def circle(t, diameter):
... # use poly(..., 36) to draw your circle with the specified diameter
You can check your function like so:
amy = turtle.Turtle()
init(amy)
diameter = 150
amy.setheading(0)
amy.fd(diameter) # move forward to draw the diameter
amy.fd(-diameter) # move back to the initial position
amy.setheading(0) # get ready to draw the circle
circle(amy, diameter)