How can I divide the environment into 4 equal parts with two line(like grid lines) in netlogo?

36 Views Asked by At

In my code, agents are positioned according to their internal ideas and external opinions. I want to see the agents whose inner idea and outer idea are the same along the middle diagonal line, so I want to separate the environment with 2 lines.

to updatePosition
  resize-world -10 10 -10 10 ; x ve y ekseni sınırlarını genişlet

  let axis-x (world-width - 5) ; substractşng 5 because getting a better visualation
  let axis-y (world-height - 5) ; substractşng 5 because getting a better visualation
  ask turtles [

    ;if the corresponding coordinate of Ai(internal idea of an agent) or Bi(external idea of an agent) of the agent is bigger than world border we limite it to world border.

    let clamped-Ai Ai
    let clamped-Bi Bi

    if clamped-Ai > 5 [
    set clamped-Ai 5
    ]
    if clamped-Ai < -5 [
    set clamped-Ai -5
    ]

    if clamped-Bi > 5 [
    set clamped-Bi 5
    ]
    if clamped-Bi < -5 [
    set clamped-Bi -5
    ]

    let scaled-x (axis-x * clamped-Ai / 10)
    let scaled-y (axis-y * clamped-Bi / 10)

    ; Turtlenin pozisyonunu güncelle
    setxy scaled-x scaled-y
  ]
end
2

There are 2 best solutions below

1
lmf0845 On

Not 100% sure what you are asking for, but patches or turtles on the diagonal have equal absolute coordinates.

Here is an example how to color patches on the diagonal. The abs reports the absolute value, which means that the negative sign is ignored.

ask patches with [abs pxcor = abs pycor] [set pcolor green]

Same applies for turtles, just using xcor/ycor instead of pxcor/pycor.

If you are looking for something like a coordinate system you can find those by their xcor or ycor being equal to 0. Here an example for turtles

ask turtles with [xcor = 0 OR pycor = 0] [set color red]
0
LeirsW On

If you want something purely visual that the turtles can't interact with, you could use the pendown (or pd) procedure for turtles.

Here I create a turtle, make him draw an x by moving from corner to corner (pick up the pen in the middle so that you don't draw a side line) and then finally let him die once his task has been fulfilled. All still within the initial brackets so the turtle won't interact with your other turtles either. I should note that this code only works if world wrapping is turned off. If it is on the turtle will go the now shorter route which is through the edges of the map.

to draw-x
  
  crt 1 [
    setxy min-pxcor min-pycor
    set color red
    pendown
    setxy max-pxcor max-pycor
    penup
    setxy max-pxcor min-pycor
    pendown
    setxy min-pxcor max-pycor
    die
  ]

end