Chrysa Pap
Chrysa Pap

Reputation: 1

More patches per turtle according to its size Netlogo

I 'm new in Netlogo programming. I would like to make turtles with cloud shape and big size so if another turtle i.e. a person be at the same patch with the cloud to lose energy. The problem is that I can't have a turtle to be in more than one patches, netlogo "can see" that it's in only one patch.

Upvotes: 0

Views: 115

Answers (2)

Jasper
Jasper

Reputation: 2790

As JenB said, the turtle only exists as a point, you'll have to come up with logic to make the clouds seem bigger than they are if you want them to be turtles.

Here is some code that demonstrates how to use size and in-radius to make the clouds breed affect the leaves breed color as they move past. It works best with shape = "circle" since then the radius of the cloud will match where the leaves are affected. You can add this code to a basic new NetLogo model to see it work:

breed [ clouds cloud ]
breed [ leaves leaf ]

to setup
  clear-all
  
  ask patches [ 
    set pcolor blue + 2 
  ]
  
  create-clouds 10 [
    set xcor random-xcor
    set ycor random-ycor
    set size 1 + random 4
    set color white - 2 
    set shape "circle"
  ]
  
  create-leaves 35 [
    set xcor random-xcor
    set ycor max-pycor
    set shape "leaf"
    set color green
    set heading 180
  ]
end

to go
  ask clouds [
    ask leaves in-radius (size / 2) [
      set color (color - 1) 
    ]
  ]
  
  ask leaves [
    fd (1 + random 10) / 10
  ]
end

You can also reverse the logic a bit so it's the leaves that check if they are inside a cloud using distance. I find this option more confusing, but it might work better in your case:

to go-leaves   
  ask leaves [
    if any? clouds with [distance myself < (size / 2)] [
      set color (color - 1)      
    ]
    fd (1 + random 10) / 10
  ]
end

And finally, instead of using turtles to represent your large areas that turtles move through, you could use patches instead. It would simplify some things, but wouldn't work in every case.

Upvotes: 0

JenB
JenB

Reputation: 17678

Regardless of the size of an icon depicting a turtle, the turtle is located only at a single point (defined by the variables xcor and ycor). However, you can instead use distance to find if other turtles are close

Upvotes: 0

Related Questions