Vous êtes sur la page 1sur 4

Net Logo- The net logo world wraps around and uses infix notation

Turtles
Agents that can move
By default, there are no turtles in the Net Logo world
Turtle Properties (not all)
Color
Size
Xcor
Ycor
Heading (measured in degrees, with 0 pointing north and 90 pointing east)
Shape
Who (unique ID #, starts with 0)
Patches
Agents that cannot move
Make up the background of the Net Logo world
Square boxes
By default, patches are setup in a 33 x 33 grid (1089 patches)
Patch Properties
Pxcor
(unique for every patch
Pycor
integers only, 6 each side)
Pcolor
Observers
Has control over the Net Logo world
No visual representation of the observer
There is always 1 observer
Commands- Every net logo command has a specific context (turtle, patch, observer)
Observer
Clear All (ca)- Kill all turtles, reset patch properties
Create-Turtles (crt n)- Create n turtles at the origin. Colors and heading random
Create-Ordered Turtles (cro n)- Create n turtles at origin. Colors assigned based
on a pattern. Headings evenly spaced starting at 0.
Turtle- Will be applied to ALL turtles
Forward (Fd n)- Move forward n spaces (1 space = 1 patch). If it is on a diagonal,
it might not necessarily be in the next patch
Backward (Bk n)- Move the turtle back n spaces
Right (Rt n)- Rotate turtle clockwise by n degrees (n can be +, -, < 360, > 360)
Left (Lt n)- Rotate turtle counterclockwise by n degrees
Pen down (pd)- Tutle will draw wherever it goes. It will be the same color as the
turtle. It can be changed, but is generally kept the same.
Pen up (pu)- It will no longer draw
Die (die)- clears all turtles, but leaves everything else
Parenthesis are not required, but can be used as organizers, Brackets are necessary

Procedures/ Functions
All procedures begin with to and finish with end
to name [a b c ] commands end
If you have parameters, they go in [ ] right after the name
Parameters arent used that often in net logo
The context is determined by the first command in the procedure
To square [ n ]
Pd
Repeat 4 [
Fd n
Rt 90 ]
Pu
End
Set

Changes a mutable property (Excludes turtles- who, patches- pxcor/ pycor)


Set property value
Set size 5
Set color red (red = 15)
Colors are numbers. Black ends in 0. White is 9.9. There are only 14 base colors
that are named. These true colors end in 5.
Set shape turtle (quotes are necessary)
Turtles directly interact with the patch its on top of
Buttons need parameters
Use Forever button (instead of repeat)
Sliders take variables Set variables (1 is standard increment). Variable created available anywhere.
Parameters can be replaced by sliders
Monitors monitor condition (Reporter)

Booleans and Conditionals


Booleans values- True and False
Boolean operators- And, or, not (goes in front)
Comparison operators- >, <, >=, <=, =, != (not equals)
If (condition) [commands]

If condition is true, commands are executed. If false, nothing happens.


Ifelse (condition) [command(s) 1] [command(s) 2]
If condition is true, commands 1 are executed. If false, commands 2 are executed
Random n
If n is a positive integer, return a number such that 0 random < n
If n is a negative integer, return a number such that n< random 0
Mod (like remainder)

21 mod 4 = 1

If statements are not connected. Each if statement is performed individually. It is possible for
nothing to happen. Ifelse is necessary to interconnect the statements.
Ifelse (random 4 = 0) [set pcolor magenta]
[ifelse (random 3 = 0)
[set pcolor cyan]
[ifelse (random 2 = 0)
[set pcolor violet]
[set pcolor lime]]]
Count agentset
Returns the total number of agents in the given set
Count patches = 1089
Agentset with condition
Returns an agent set that only contains the agents that satisfy the condition
Patches with [pcolor = magenta]
The empty set is called nobody (if no agents satisfy)
Wiggle- Common name for a custom procedure that creates random turtle movement
Usually turtles move forward 1 space
It will wait .1 seconds to perform (for forever buttons) because it will go in a blink of an eye
otherwise.
For insanity (slider)- smaller numbers are more circular and cover larger area. It is less likely to
double back. You can slide as it runs
Going right then left will be straighter
To wiggle
Wait .1
Rt random insanity
Lt random insanity
Fd 1
End
Cro/ Crt n [turtle commands]
All and only the newly created turtles obey. Old ones do nothing.
Custom properties
We can add our own properties to turtles and patches
To add your own property, at the top of the procedures tab:
Turtles-own [property]
Patches-own [property]
You can declare multiple properties in one line
All custom properties will start with a default value of 0
You can right click the turtle
Inspect- Properties of turtle (turtles-own [n] is included)
Ask

Ask agent/ agentset [commands]

Give commands to the specified agent or agenset


Only observer can ask all of the turtles/patches
Ask turtles [fd 3]
Ask turtle 0 [rt 30]
(turtle 0 is who#)
Ask patch 1 12 [set color blue] (1 is pxcor and 12 is pycor)
Ask patches with [pxcor > 0] [set pcolor red]

n-of

N-of x agentset (x is a positive integer)


Return x agents from the given set at random
N-of 1089 / 3 patches (exactly one third of the patches)
One-of agentset
One-of turtles with [color = green]

[property] of agent
(not agent set)
Returns value for given property of the given agent
[size] of turtle 3
Set pcolor [color] of turtle 0

Of

Vous aimerez peut-être aussi