or keissar
or keissar

Reputation: 125

set turtles in specific location netlogo

Right now i have the following code for initial planning of "plants" and i want them to be in a grid formation and not randomly (something like a real field, like in the picture attached):

enter image description here

This is my code:

;;init plants
  set-default-shape plants "plant"
  create-plants initial-number-plants [
    set color green
    setxy random-xcor random-ycor ;they are spread out randomly

    set is_susceptible true
    set is_infectious false

   ]

Any help would be appreciated.

Upvotes: 0

Views: 537

Answers (1)

JenB
JenB

Reputation: 17678

Easiest option is to use sprout instead of create. Leave a comment if this is not enough information and I will write out the full code.

UPDATE: full procedure (assumes you have a turtle breed called 'plants' with variables about susceptibility and infectivity). I also slightly changed your variable names to add the ? at the end, which is a NetLogo convention for true/false variables.

to setup-plants
  set-default-shape plants "plant"
  ask n-of initial-number-plants patches
  [ sprout-plants 1
    [ set color green
      set is_susceptible? true
      set is_infectious? false
    ]
  ]
end

Note that this code will break if you have more plants than patches. Your diagram has exactly one plant per patch so I wasn't sure what you wanted.

Upvotes: 1

Related Questions