11-19-2013

posted Nov 19, 2013, 5:33 AM by Samuel Konstantinovich   [ updated Nov 19, 2013, 6:32 AM ]

Goal: lab writing functions in netlogo

Do Now: (On Paper)

0. Log in while you work on your do now. Turn the monitor off after you did this.

1. Write code (specify the context of each command) that creates a turtle and then moves the turtle to (3,4) using forward and other directional commands.

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

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

4. You can make that into a function. Would you want to write a function for each polygon that same way? What about all the functions up to a 100-gon?


Classwork1:

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



to triangle [n]

  pd

  repeat 3 [

    fd n

    rt 120

  ]

end


Comments