Netlogo - How to get your turtle to the top?

For example, I have 10 turtles on one patch, how do I move a specific turtle (a turtle with [color = red]) to the beginning? Thanks for the help!

+3


source to share


2 answers


I'm guessing the question is about the "z-order" of the turtles and that "moving the turtle up" means "did it draw on top of the others".

There are two factors that determine the coloring order in NetLogo: breeds and numbers ẁho

. Breeds have priority. According to the Breeds section in the Programming Guide :

The order in which the rocks are declared is also the order in which they are layered in the view. Therefore, the rocks defined later will appear on the tops of the rocks defined earlier;

Turtles of the same breed are colored in the order of their creation (displayed in NetLogo by number who

): older ones are colored first, and new ones - on top.

The order of creation cannot be changed, but if nothing in your code is holding onto turtle references or numbers who

(the latter is impractical anyway), you can use hatch

to create a turtle clone and then destroy the old one immediately. For example:



to setup
  clear-all
  create-ordered-turtles 10 [ set size 10 ]
  ask turtles with [ color = red ] [
    hatch 1
    die
  ]
end

      

The last line would bring all the red turtles (in this case only) from above.

What if you can't do it for some reason? Then you can use breeds:

breed [ background-turtles background-turtle ]
breed [ foreground-turtles foreground-turtle ]

to setup
  clear-all
  create-ordered-background-turtles 10 [ set size 10 ]
  ask turtles with [ color = red ] [
    set breed foreground-turtles
  ]
end

      

You will need as many breeds as you want "layers" of turtles. It may or may not be convenient. The best approach will depend on your specific use case.

+3


source


There is some ambiguity.

To move the turtle to the top of the patch

 Set ycor pycor + .5

      



To move it to the beginning of the view

 Set ycor max-pycor

      

To make it the top of the stack in photoshop style. Not so easy. the turtles are displayed in the order of their IDs. Who cannot be changed. So if you want red on top, either make it last or change the values ​​with turtle on top. Unfortunately.

+1


source







All Articles