* Use functions to avoid repetitive code
* Explore the difference between declaring a function and calling it
* Defining your own functions using the turtle module
* Calling functions within other functions
* Practice with incremental development
You will write a program through which you can draw leaves, twigs, branches, and ultimately trees, like the ones to the right.
You will accomplish this task by completing several subtasks. Make sure to do these subtasks in order.
You are free to design your tree however you'd like: your functions may use parameters or not, and may or may not have return values. However, there are two restrictions: each function must draw something, and except for main, they must each move the turtle back to wherever it started when the function was called.
Since you'll be working with turtles, make sure to download turtleBeads from this folder. In a new file, called username_TreeParts.py, make sure to import all the turtle modules, as we've seen in class. For example, this is how Beyoncé Knowles would name her file: bk134_hw3_treeparts.py. This is the file you'll be submitting at the end.
The leaf function has been provided for you, but you are free to modify it, including by changing the number of parameters used, what it draws, or the return value. The provided leaf function illustrates one strategy for returning the turtle to where it started: after drawing what you want to draw, move backwards retracing your steps to get back to where you started.
It does still need to draw something.
Task B. twig
The twig function must draw something, and must call leaf at least twice. As with leaf, it must put the turtle back where it started when it's done.
Note that you should NOT use the setHeading function (unless it measures the current heading first) since we will test your twig function using multiple starting angles.
The example below shows how the twig function could work, but remember that you're free to have it draw whatever you want, and you do not have to stick to the suggested parameters or return value.
Task C. branch
Just like the twig function, the branch function must:
* Draw something,
* call twig at least twice,
* put the turtle back where it started when it's done
* Also, it must call either left or right to turn the turtle at some point.
This example shows one way the branch function could work.
Task D. tree
The tree function must:
* Draw something,
* call branch at least twice,
* put the turtle back where it started when it's done
* call either left or right to turn the turtle at some point.
This example shows one way the tree function could work.
Task E. main
Because you're free to design your tree function with any number of parameters, there's no way for us to call your tree function directly. To solve this issue, you must define a main function which has zero parameters and which calls your tree function at least once. Unlike the other functions, the main function does not need to call any drawing functions directly. It must complete without crashing, however.
This example shows one way the main function could work.
- Include comments, at the top of the file, describing the author, any collaborators, the version, etc (as seen in previous examples).
- Each function you define must include a docstring.
- You should not waste fruit and you should not waste boxes. "Wasting fruit" means calling a fruitful function but ignoring the result. "Wasting boxes" means storing the result of a non-fruitful function (which will always be None) in a variable (a.k.a., box).
- You should not define any functions inside of other functions (this is not particularly useful).
- For full credit, your program should not crash or generate any errors.
Make sure that your file:
Starts with a comment indicating your name, the date, and any collaborators
Save your python file as LastnameFirstInitial_TreeParts.py, e.g, this is how Beyoncé Knowles would name her file: bk134_hw3_treeparts.py
Each function has a docstring
Each function is tested properly
Submit this file in gradescope