Lab 2 - Turtle drawing with functions
Due Feb 13, 11:59pm
Moodle Link
|  |
Goal
To learn about funtions and Turtle graphics
Turtle Graphics functions
Method
1. First consider the simple the code below:
Note it uses no comments.
2. Consider a better version below, with functions:
3. Start a new repl.it with the previous code.
4. Finish the
drawPolygon and
drawRectangle functions. Draw several Polygons and rectangles.
5. Add a color option, and color fill option to every object type. (add parameters to do this)
6. Rewrite the
drawSquare and
drawTriangle functions use the
drawPolygon function to do the work.
7. Finish the
drawHouse function. The house should make use of the other functions to make a house with a roof, a door, some windows, and anything else you feel is nice. The house should use color and fill to make it look nice. The trick is the make the house
scalable. In order to do that you will need to draw everything relative to the starting position of where you start the house. An example of a scalable drawing is below. Not that I use a function I wrote called
moveRelative to move relative to my current position, and thus moves are a fraction of the size. Notice also that the size of everything is a fraction of the original size. Thus when change the size of the object, everything in the object scales accourdingly.
Hint: The line below saves the current position of the turtle in the variable spos:
sPos=t.pos()
The line below move the turtle back to the position saved in spos.
moveTurtle(t,sPos[0],sPos[1])
You can use this to make it easier to figure out where to draw components of your items.
8. Make a function
drawPerson to draw a stick figure of a given size, color and fill. This should be scalable too.
9. Make function "
buildNeighborhood(t,h,p) that displays 3 houses, and 5 people. Your goal is to try to make the sizes of the elements in a range that makes sense (not to big or small), and that are actually on the screen (not in some far of location). The program should also put a sun in the sky using the built-in
circle function.
10.
Extra credit:
- 5% - Pick random colors for the houses and people
- 10% Place the houses and people on the screen in random locations choosen each time you run the program (with a random number generator). IT is ok if items overlap each other.
- 10% Have the buildNeighborhood actually place the houses on the screen by where you click with the mouse. E.g. 3 clicks for the 3 houses, and 5 clicks for the 5 people. (10%) (Example here: repl.it
)
Grading
Turn in a Repl.it link, as well as screenshots of three runs
Requirements | Grading Comments | Points | Score |
Completion of all functional requirements | | 60 | |
Code broken up in small, single function functions | | 10 | |
Appropriate code formatting | | 5 | |
Meaningful identifier names (variables, functions) | | 10 | |
Comments at the top, and on all functions | | 5 | |
Document with screen capture of picture | | 10 | |
Extra credit | | (25 max) | |
Total | | 100 |
|
SolutionWeb.SolutionLab2
*