2014-11-20 HW

posted Nov 20, 2014, 5:10 AM by Samuel Konstantinovich   [ updated Nov 20, 2014, 7:16 AM ]

Goal: lab writing functions in netlogo

Do Now:

1. Write a function that creates a turtle and then moves the turtle to (3,4) using forward and other directional commands.

2. Write a function that creates a turtle and then moves it to (-2,1) using the set command.

3. Write a function that makes all turtles draw a square with side measure 2 units, and returns the turtle to it’s original orientation.

Would you want to write a function for each polygon that same way like hexagon,pentagon? What about all the functions up to a 100-gon?

Homework: (bring a digital copy to school, you need a working copy)

We could write functions that draw single shapes but it would be so much better to make one function for all regular polgons.

Triangle draws a side and turns 120 degrees. It does this 3 times.

Square draws a side and turns 90 degrees and draws a side. It does this 4 times.

Write a function that would take a parameter n and s. It will draw an n-gon with side measure s. 

n-gon 5 2    would make the turtle draw a pentagon with side 2

n-gon 10 1  would make the turtle draw a decagon with side 1

n-gon 20 .5  would make the turtle draw an icosagon with side .5


Comments