Netlogo add the average distance information on patches from the patch 3 -3 - distance

I would like to know how to design this.
All patches will compare their own distance from the patch [3 -3] with the average distance. So they realize that they are closer or far from the average distance.

globals [ref-patch av-dist]
to setup
ca
set av-dist mean [distance patch 3 -3] of patches
demo
end
to demo
ask patches [
if distance patch 3 -3 < av-dist [
set pcolor red
]
]
end

I think I would put everything in a patch reporter like this:
to-report closer-than-average?
report distance patch 3 -3 < mean [distance patch -3] of patches
end
Then you can
ask one-of patches [show closer-than-average?]
or
ask patches with [closer-than-average?] [set pcolor blue]
etc.

Related

Is there a way to kill a certain number of turtles within a radius of a patch with a certain color in Netlogo?

I am very new to Netlogo and I am trying to simulate culling of turtles within a certain region based on the characteristics of the patch. Within my model landscape, I have one single patch that is orange. I want 50% of turtles within 5 pixels of that patch to die. I would also like this process to continue every year after the first year of the simulation (this part I think I have). Can anyone help me?
if d = 10 [
if year >= 2 [
let ring nobody
set ring patches in-radius 5 patches with [pcolor = orange]
ask turtles-on ring [die]
]
]
in-radius reports agents that are within a certain distance from the caller, so the orange patch must be the one calling in-radius.
The code in your example is not reproducible, so I'll make an arbitrary example:
to setup
clear-all
ask one-of patches [
set pcolor orange
]
create-turtles 100 [
setxy random-xcor random-ycor
]
end
to go
ask patches with [pcolor = orange] [
ask turtles-on patches in-radius 5 [
if (random 2 < 1) [die]
]
]
end
Note that in-radius reports agents within a certain distance, where the unit of measure of distance is a patch`s side.
Identifying patches within a certain distance and then asking all turtles on those patches to die (as in the example above, which follows the approach in your question) has a different effect than asking all turtles within a certain distance to die.
Which of the two approaches fits your case is something that you have to decide. Below, the code that would address turtles directly:
to go
ask patches with [pcolor = orange] [
ask turtles in-radius 5 [
if (random 2 < 1) [die]
]
]
end

netlogo patch affected by distance from a certain patch

I would like to ask how i can set up patches.
Initial condition is there is a red patch at a certain point. The other patches will be affected by a distance from the red patch. As a distance go far, the impact will be greater.
It might not be simple as a beginner. please help me out!
Edited to include Nicholas' commends
to example
let red-patch one-of patches with [pcolor = red]
ask red-patch [
ask other patches [
if random-float 1 > (distance red-patch / (max [distance red-patch] of patches))
[set pcolor blue]
]
]
end
This would have it be a gradient effect so they are more likely to be blue the closer they are to the red patch. Flipping the > to a < just inverses the effect.

How to setup one patch with a particular colour in Netlogo?

Why does this work:
to setup
clear-all
ask n-of 1 patches [set pcolor green]
end
But this doesn't:
to setup
clear-all
ask patch-at 1 1 [set pcolor green]
end
How do you have the patch at 1 1 change colour please?
Thank you.
You need to do the following:
to setup
clear-all
ask patch 1 1 [set pcolor green]
end
Your code is using patch-at which reports (ie tells the asking agent) the location or patch coordinates of the patch which is at a certain position (in this case, 1 up and 1 right) from the asker. That is, a relative position. Instead, you are wanting to ask a patch with specific coordinates or absolute position so you use the patch's name such as patch 1 1.

Create more than 1 turtles on patchset

How to create more than 1 turtles on patchset such that no two turtles have the same center?
Number of turtles to create defined as density.
Therefore, I require more agents per patch.
Eluciadtion: There a a set of patches in shape of box in which I wish to fill agents. Equivalent to distributing agents in a room.
This answer Distribute turtles on patches would create turtles outside the box as well.
Thanks.
Assuming patchset means all the patches.
Crt number
[Setxy random-xcor random-ycor]
Gives you a number of turtles uniformly distributed on the patches with a very small chance of having the same center. The birthday problem with floating points.
Or this if you want n turtles uniformly distributed on any set of patches P.
Repeat n [ask one-of p
[
Sprout 1
setxy (pxcor + random-float 1 - .5) (pycor + random-float 1 -.5)
]
]
Pick a random member of your set and put a turtle on a random part of that patch
If density is literally the number of turtles to create and my-patches is your patchset:
ask n-of density my-patches [ sprout 1 ]
If density is the fraction of patches that should have turtles on them (e.g. density = 0.5 would mean half the patches should have turtles):
ask n-of (density * count my-patches) my-patches [ sprout 1 ]
If density should be treated probabilistically (e.g. density = 0.5 would mean each patch has a 50% chance of having a turtle):
ask patches with [ random-float 1 < density ] [ sprout 1 ]

NetLogo - find minimum angle between two patches in patchset

I'd like to find the set of patches that constitute the convex hull around a set of patches belonging to the turtle's territory. I was planning to use a "gift wrap" procedure to calculate the convex hull (related to below picture).
I'm first finding the territory patch with the lowest pxcor to start at. Then, I'd like to find the territory patch that has the smallest heading (i.e., angle closest to zero) from the starting patch, and so on, until I arrive back at the starting patch. But I can't seem to figure out how to calculate headings between two patches. Any suggestions would be really helpful. Here is what I have so far. Eventually I will have to make this loop through each point along the outer hull.
patches-own [ owner-animal ]
turtles-own [ territory ]
to setup
ca
create-turtles 1
[
move-to patch-at (max-pxcor / 2) (max-pycor / 2)
set territory patches in-radius (2 + random 8)
ask territory [
set owner-animal myself
set pcolor [ color ] of myself - 2
]
]
end
to find-convex-hull
ask turtles
[
let start-patch min-one-of territory [pxcor]
ask start-patch
[
let next-patch min-one-of [territory] of myself [towards self]
]
]
end
I think this does what you're looking for. The only odd thing about the code is the [towards myself - heading] of myself] in which the first myself refers to the next turtle and the second myself refers to original, because it is the myself of the myself.
Does that make sense? Let me know if you have any questions.
to setup
ca
crt 10 [setxy random-xcor random-ycor]
end
to start-connecting
ask min-one-of turtles [xcor][set heading 0 connect]
end
to connect
let the-turtle min-one-of other turtles with [[towards myself - heading] of myself > 0] [ [towards myself - heading] of myself]
if the-turtle = nobody [stop]
face the-turtle
ask the-turtle [set heading [heading] of myself]
create-link-with the-turtle
ask the-turtle [connect]
end
By the way, if you only want to do this for particular agentsets, just change which turtles you connect with in the connect procedure.