2017-10-16

posted Oct 16, 2017, 6:20 AM by Konstantinovich Samuel   [ updated Oct 16, 2017, 7:02 AM ]
Do now: ON PAPER: Write the commands needed to accomplish this, as well as what context you need to use each of them.

Now I expect everyone to be able to do the following:
-Create 100 turtles
-Move them each to random locations on the world (are there multiple commands for this?)
-set all of their sizes to 4, and their shapes to cow.

Note: there are shortcut names for most functions, rt, lt, fd, bk, crt, cro etc. You may use these.


Goal: Functions vs Procedures

-You have dealt with Functions in Scheme, they evaluate an expression and return a value.
-In Netlogo another kind of function is called a procedure, and it just executes commands but does not return a value.
Since most programming languages even functions can execute a series of commands, so the only effective difference is that procedures do not return a value.

Semicolons are comments in netlogo.

to procedureName
  ;BODY OF PROCEDURE HERE
end

to forwardTwice
  fd 1
  fd 1
end

to sideStep
  rt 90
  fd 1
  lt 90
end

Some procedures (and almost all functions) have parameters:

to sideStepNtimes [ n]
  repeat n[
    rt 90
    fd 1 
    lt 90
  ]
end

Or more than one parameter:

to moveAndTurn [ n a ]
  fd n
  rt a
end

Netlogo Lab01:
After writing a procedure you must test it. Make sure it behaves as described. Make sure you try telling more than one turtle facing more than 1 direction.

0a. Write an observer-context procedure   setup
It must: 
-Destroy everything in the netlogo world. 
-Create 20 turtles

0b. Write an turtle-context procedure   setup2  (you will tell all turtles to run this)
It must make the turtle that runs this command:
 -move to a random position.
 -change the size to 3.
 -change the shape to turtle.

1a. Write a turtle-context procedure  triangle s
Any turtle that runs this command will draw an equilateral triangle with side length s.
At the end of this procedure, the turtle should be facing the same direction it originally started in.

2a. Write a turtle-context procedure  square s
Any turtle that runs this command will draw an square with side length s.
At the end of this procedure, the turtle should be facing the same direction it originally started in.

3a. Write a turtle-context procedure  n-gon n s
Any turtle that runs this command will draw a polygon with n sides, and side length s.
At the end of this procedure, the turtle should be facing the same direction it originally started in.
3b. What are values for n that would be bad inputs? We will ignore these for now.

4. Look in the netlogo dictionary at the random and random-float commands. 
4a How can you generate a random integer from 2-4 inclusive? Test your command and verify.
4b How can you use this tool to have each turtle draw a different n-gon?
4c What is a good range of numbers to test on? ( remember what a bad input is)


-Lab/HW you must submit:
 Your netlogo procedures 
 Your answers to the prompts (using netlogo comments for these answers as they are non-code questions)

Submit them on the homework server as a homework server comment by tomorrow 8am.




Comments