Reputation: 69
I'm quite new to NetLogo and I want to use the below code to create a world of green and red circles, but the below code doesn't work with the color as it is only grey? any advice?
to create_turtles
ca
ask patches [ sprout 1 ]
ask turtles [ set shape "circle" set color green]
end
Upvotes: 0
Views: 39
Reputation: 96
I just tried your code and it works just fine except it just create all green turtles (circles). If you want it red and green, I suggest you add some piece of code in the ask turtles
command and may I suggest you to use the indentation style as well (usually NetLogo will do it automatically):
to create_turtles
ca
ask patches [ sprout 1 ]
ask turtles
[
set shape "circle"
set color green
let chooser random 2
ifelse chooser = 0
[ set color green ]
[ set color red ]
]
The let
procedure is a local variable assigner and we let the value a random number of 0 and 1 (two numbers, hence the random 2
, and primitive random
always include 0 as first number).
In that example we ask the circles to randomly choose a number between 0 and 1. If it chooses 0 then it will set it color to green, otherwise red.
You can explore more about those primitives in the NetLogo Dictionary.
Upvotes: 2