# Lab 2 - Turtle drawing with functions

### Goal

To learn about funtions and Turtle graphics

### Method

1. First consider the simple the code below:

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)

Turn in a Repl.it link, as well as screenshots of three runs

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

*

Topic attachments
I Attachment History Action Size Date Who Comment
png Screen_Shot_2018-09-19_at_1.09.38_PM.png r1 manage 56.1 K 2018-09-19 - 17:12 JimSkon
png Screenshot_20180918_001125.png r1 manage 10.3 K 2018-09-18 - 04:12 JimSkon
png Screenshot_20180919_151657.png r1 manage 15.8 K 2018-09-19 - 19:18 JimSkon
png Screenshot_20180919_152651.png r1 manage 18.1 K 2018-09-19 - 19:33 JimSkon
Topic revision: r15 - 2019-09-24 - JimSkon

 Home Main Web P View Edit Account
Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback