How to draw patches situated in crossroads? - netlogo

How can I draw in red the patches situated in crossroads (the roads are drawn in white) as in the figure below ?
Here is my beginning of code:
ask patches with [ (pcolor = white) and (pxcor mod (nb-patch-length + 1) = 0 ) and (pycor mod (nb-patch-width + 1) = 0 ) ] [set pcolor red]
Thanks in advance for your help.

How about this? (Assuming roads are one patch in width and are always horizontal or vertical.)
ask patches with [all? neighbors4 [pcolor = white]] [set pcolor red]

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.

Nested if queries in patch context NetLogo

I want to change color of patches to green under these conditions:
-IF there are any two blue patches on same column and their distance is smaller than 25 AND
-IF there are any yellow patches on same column and between these selected blue patches
-Then change color of all patches satisfying these conditions to green.
I am struggling to make it in NetLogo, tried using nested loop but couldn't find a way. Thank you for any help. And I have added a sample image which I want to achieve and marked example blue patches.
As addition, to show what I want to do in code (sorry about code):
if any? patches with [pcolor = blue and
(if any? patches with [pcolor = blue and pycor = ?(selected_first_blue's_pycor)
if any? patches with [pcolor = yellow and pycor < ??(selected_first_blue's_pycor) and pycor > ?(selected_second_blue's_pycor)))
[ask patches [set pcolor green]]
The way you are approaching it, you need fairly convoluted statements like:
let upper-blues patches with [color = blue and
any? other patches with [color = blue and pxcor = [pxcor] of myself
and pycor < [pycor] of myself and pycor > [pycor] of myself - 25]
I believe this would be much easier to take the perspective of the patch you want to potentially turn green. If I have interpreted your conditions correctly, that patch needs to work out the closest yellow patch above/below/at and then check if there are two blue patches bracketing both the yellow and itself with the blue patches sufficiently close to each other. I assume you have wrapping turned off.
Here is a complete model that puts in a red turtle instead of turning the patch green so you can see whether it is identifying the correct patches.
to setup
clear-all
ask patches [set pcolor white]
ask n-of 100 patches [set pcolor blue]
ask n-of 100 patches [set pcolor yellow]
end
to convert-to-green
let turn-green nobody
ask patches
[ let my-column patches with [pxcor = [pxcor] of myself]
let above-yellow min-one-of my-column with [pcolor = yellow and pycor >= [pycor] of myself][pycor]
let above-blue ifelse-value (above-yellow != nobody) [min-one-of my-column with [pcolor = blue and pycor > [pycor] of above-yellow][pycor]][nobody]
let below-yellow max-one-of my-column with [pcolor = yellow and pycor <= [pycor] of myself][pycor]
let below-blue ifelse-value (below-yellow != nobody) [max-one-of my-column with [pcolor = blue and pycor < [pycor] of below-yellow][pycor]][nobody]
if above-blue != nobody and below-blue != nobody and ([pycor] of above-blue - [pycor] of below-blue < 25)
[ set turn-green (patch-set self turn-green)
]
]
ask turn-green [sprout 1 [set color red]]
end
Once you are satisfied it is working correctly, change ask turn-green [sprout 1 [set color red]] to ask turn-green [set pcolor green].
This code checks each patch in random order and adds it to the set of patches (called turn-green) if the conditions are satisfied. Once all patches have been tested, the set of selected patches then change their colour. This avoids issues of yellow or blue patches turning green and not being available for later patches to check against.

coloring patches with specific in a domain

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

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