coloring patches with specific in a domain - netlogo

I want to have pcolor of my outer-ring patches as green
I have written following command
To setup
ask patch 0 0 [ set pcolor red
ask neighbors
[ set pcolor blue]
ask patches with [pxcor > 1 and pxcor < -1 and pycor > 1 and pycor < -1]
[set pcolor green ]
]
end
I get center and neighbors with required color but out ring of patches remained black.
plz help.

The problem is that you provide a condition that no patch can satisfy. (E.g., it cannot be both to the left of your colored patches and to the right, but you use and.) Does the following meet your needs?
to colorPatches
ask patch 0 0 [
set pcolor red
ask neighbors [ set pcolor blue]
]
ask patches with [pcolor = black] [
set pcolor green
]
end

Related

How to force turtles to move only in a half of the world?

I created a world divided in two parts with the command ask patches with [ pxcor < 0] [set pcolor blue] ask patches with [pxcor > 0] [set pcolor green] .
In one of this there're 100 turtles, who 5 are infected and the same in the other part.
My problem is to force the turtles to move only in their part of the world. So I want that turtles with pcolor = blue move randomly in the second and third quadrant (pxcor <0) and turtles with pcolor = green in the first and fourth quadrant (pxcor> 0). how do I do?
This is the code:
turtles-own
[
sick?
sick-time]
to setup
ca
ask patches with [ pxcor < 0 ] [set pcolor blue] ; we want divide the world in two parts: the blue one in the north of Italy
ask patches with [pxcor > 0 ] [set pcolor green]; the white one is the south of Italy
ask patches with [pxcor = 0 ] [set pcolor white ] ; represent the border
create-turtles 200 ; we create a population made up for 200 people
[ set size 1
set shape "person"
set sick-time 0
get-healthy]
ask n-of 100 turtles ; 100 of this one live in north of Italy
[setxy 12 random-ycor ]
ask n-of 100 turtles ; another 100 in the south
[setxy -12 random-ycor
]
ask n-of 5 turtles with [pcolor = blue] ; we want infect 5 people for each world
[get-sick ]
ask n-of 5 turtles with [pcolor = green]
[get-sick ]
reset-ticks
end
to get-healthy
set sick? false
set color white
end
to get-sick
set sick? true
set color yellow
set shape "circle"
set sick-time sick-time + 1
end
to go
ask turtles
[
move ]
tick
end
to move
rt random-float 360
fd 1
end
Your movement procedure looks like:
to move
right random-float 360
forward 1
end
If you want them to just stay where they are if moving would take them into the wrong half, then you can use patch-ahead to test the patch they'd be moving to. I think what you want is that they don't go to a different coloured patch. One way is:
to move
right random-float 360
if [pcolor] of patch-ahead 1 = pcolor [forward 1]
end
[pcolor] of patch-ahead 1 returns the colour of the patch that is one distance unit ahead, so where the turtle is trying to move to. pcolor is the colour of the patch that the turtle is currently standing on.

Spatial Autocorrelation in NetLogo

Is there any straight-forward way to adjust spatial autocorrelation for three different patch colors? I am trying to control both the number of red patches and how spatially autocorrelated (how close same colored patches are to each other). I can control the proportion of red patches, but don't know how to setup the autocorrelation.
Here is my code so far:
to setup-patches
resize-world 0 15 0 15
set-patch-size 30
ask patches [
set pcolor one-of [ green brown ]
]
ask patches [
let close-patches patches with [pcolor != red]
ask n-of ((proportion-red-plants * count patches) - count patches with [pcolor = red]) close-patches
[set pcolor red]
]
end
proportion-red-plants is a slider in the interface
If you know that AC of 0 means pick a patch that has no red neighbours, and that AC of 1 means pick a neighbour of any red patch, then all that is required is to choose AC=1 method with the given probability and the AC=0 method otherwise. This is what I meant by a design issue, you need to work out the steps required before trying to code those steps.
Here is an almost solution. I haven't bothered to do things like make sure the patches being turned red aren't already red so the counts will be incorrect.
to setup
clear-all
let prop-red 0.1
let AC 0
ask one-of patches [set pcolor red]
ask n-of (prop-red * count patches) patches
[ ifelse random-float 1 < AC
[ ask one-of patches with [ pcolor = red ]
[ ask one-of neighbors [ set pcolor red ]
]
]
[ let candidates patches with [not any? neighbors with [pcolor = red] ]
if any? candidates
[ ask one-of candidates [ set pcolor red ]
]
]
]
end
Thank you JenB again for helping. This is the code I ended up using which proved to get the job done (while keeping counts of red patches correct)
to setup-patches
resize-world 0 15 0 15
set-patch-size 30
ask patches [set pcolor one-of [green brown]]
let first-patch one-of patches
ask first-patch [set pcolor red]
repeat (proportion-red-plants * count patches - 1) [ask one-of patches [assign]]
end
to assign
ifelse random-float 1 < AC
[let candds patches with [any? (neighbors with [pcolor = red])]
ask one-of candds [set pcolor red]]
[ask one-of patches [set pcolor red]]
end

Setting turtles energy diminishing differently in different areas

In NetLogo I've got 3 areas:
to setup-patches
ask patches [ if pxcor > 6
[set pcolor yellow
]
]
ask patches [ if pxcor <= 6
[set pcolor green
]
]
ask patches [ if pxcor < -6
[set pcolor blue
]
]
end
I'd like 2 of my 3 different kinds of turtles to lose energy faster as they go (tick) in one of the areas, for example in ycor > 6.
set energy energy - 1 [ -6 if xcor <= 6]
But this does not work.
Try:
ask patches with [pxcor > 6] [set pcolor yellow]
ask patches with [pxcor <= 6] [set pcolor green]
ask patches with [pxcolor < -6] [set pcolor blue]
Then, if energy is a turtle variable.
ask turtles
[
if yellow = pcolor [set energy energy - 1]
if green = pcolor [set energy energy - 2]
if blue = pcolor [set energy energy - 3]
]

Changing patch colors except one color

I'm creating a program in Netlogo which has shoppers (turtles) moving through a grocery store layout. When they step on a patch it increases in color and when it has no agent on it, it decreases in color, as this will show the paths shoppers take through a store.
My code is:
ask turtles
[ rt random 360
fd 1
set pcolor pcolor + 1 ]
ask patches with [ (pcolor > 9.9) or (pcolor < 0.1) ]
[set pcolor 0]
ask patches with [ (count turtles-here = 0) and (pcolor <= 9.9) and (pcolor > 0) ]
[ set pcolor pcolor - 0.1 ]
However, as the aisle patches are blue this is turning them back to black as well. I was wondering what code I could use so patches with pcolor = 105 will stay blue and not change to black?
Don't change the color of the patches with pcolor = 105. You'll just need to add an additional condition to anywhere you modify the patch color.
ask turtles
[ rt random 360
fd 1
if pcolor != 105[set pcolor pcolor + 1 ]
]
ask patches with [ pcolor != 105 and ((pcolor > 9.9) or (pcolor < 0.1))]
[set pcolor 0]
ask patches with [pcolor != 105 and (count turtles-here = 0) and (pcolor <= 9.9) and (pcolor > 0) ]
[ set pcolor pcolor - 0.1 ]

netlogo patch set as chess board style

how can I set al of patches like chess board. one white than black?
ask patches [if ...... [set pcolor white]
if .......[set pcolor black]]
could you say is it the right way or?
assuming your world is already 8x8 patches and the patches are default black:
ask patches [if pxcor mod 2 = pycor mod 2 [set pcolor white]]
Assuming you have an 8x8 world
to setup
ask patches [
ifelse pxcor mod 2 = pycor mod 2
[set pcolor white]
[set pcolor black]
]
end