I have imported an image over patches by using netlogo command "import-pcolors "abc.png" ".
Now i am trying to hide an image so that turtles interact with the hidden image as only by following those patches of the hidden image.
thanks in advance.
first make an extra patch variable for storing the color information:
patches-own [invisible-pcolor]
(calling it whatever you want)
then after import-pcolors do:
ask patches [
set invisible-pcolor pcolor
set pcolor black
]
and then have your turtles interact with invisible-pcolor instead of pcolor.
another solution would be to fill the drawing layer with black (or any color), e.g. by making a giant turtle of the color you want and having it do stamp then die
Related
I am trying to create a square of brown patches centered at the origin of my grid. Previously, I had a slider on the interface called "sink-patch-radius" that goes from 0 to 20. Then in my code, I created a circular set of patches centered at the origin that were colored brown + 2 and had a radius of "sink-patch-radius", and the surrounding patches were green. Here is the code that worked for that (thank you to JenB for this!):
;;create the 'sink'
let sink-centre patch 0 0
set sink-patches [patches in-radius sink-patch-radius] of sink-centre
ask sink-patches [ set pcolor brown + 2 ]
;; create the 'source'
set source-patches patches with [pcolor != brown + 2]
ask source-patches [ set pcolor green ]
So now, I want that idea to stay the same, but instead of a circular "sink area", I want it to be a square. I know the above code will have to change, maybe even quite a bit, because you cannot use "in-radius" to make a square. I'm thinking of maybe changing the slider to be "sink-patch-length" so that it adjusts the length of the sides of the square. My question would then be: how do I incorporate that into my code, so that I get a square of brown patches centered at the origin? For example, if "sink-patch-length" is set to 20, then I would want a 20x20 square (400 cells) centered at the origin to have a pcolor of brown + 2.
Any help is greatly appreciated! Thank you.
Use the inbuilt coordinate system. So you want (something like) patches with [abs(pxcor) <= sink-patch-length and abs(pycor) <= sink-patch-length]. If you want it centred somewhere other than the middle, you will need to do some fiddling to make the boundaries correct.
I have some netlogo code that I would like to make more descriptive.
So instead of:
MOVE-TO ONE-OF PATCHES WITH [ PCOLOR = BLUE ]
It would say:
MOVE-TO ONE-OF PATCHES WITH [ WATER ]
In java I would create an enum to accomplish this. How can I do it in Netlogo?
Alan's answer is fine, but I would also consider the possibility of creating a patch variable instead of relying on the patch color. For example:
patches-own [ water? ]
If you set this to true for each water patch, you can then say things like:
move-to one-of patches with [ water? ]
The main reason for doing this is that you might want to change the color of the water patches at some point: make them a slightly darker or lighter blue, for example, or use color to temporarily highlight patches with some other characteristic.
Separating presentation and program semantics is generally good practice.
Another, different way to achieve this would be to create an agentset with your water patches during setup. For example, supposing you declare water-patches as a global variable, you would do:
set water-patches patches with [ pcolor = blue ]
And then you can do:
move-to one-of water-patches
The water-patches agentset is not affected if you change the color of a patch. It might also be a bit faster since you only construct it once instead of filtering over all patches over and over again.
to-report water ;patch proc
report pcolor = blue
end
Alan's answer is perfectly fine, but this question suggests to me a different conceptualisation. What you really mean is that the patch is coloured blue because it is water, but you are coding it the other way around so that colour is indicating its status as water. If other aspects of your model (eg travel speed, type of crops) depend on whether it is water or not, then you could consider a different construction.
patches-own
[ water?
]
to setup
ask patches
[ set water? FALSE
if random-float 1 < 0.2
[ set water? TRUE
set pcolor blue
]
]
end
In this construction, you have a true/false variable for each patch that indicates it is water (if true). Then you can directly have statements such as ask patches with [water?] []. You can also set up a global variable that holds the patch-set of water patches and then make statements like ask water-patches []
If you have multiple types of land style (eg water, sand, soil, rock...) then you colour is more likely to be the way to go since you don't want separate variables for all of these. Even then, though, you could have one attribute for land style and have constructions that are ask patches with [ type = "water"]
In Net Logo is there a value for a turtles Z coordinate, or its height in the 3D View? I have white patches in my simulation, when my turtles go into those patches they are not visible until they emerge from the other side of the patch.
In the screen shot, you can see edges of turtles inside of my white patches, I want to display them on top of the patch.
How can I do this?
I found the issue, simply use
set zcor 2
will place the turtles on top of the patches as I had hoped.
I'm trying to make a Frogger-like game where the patches move around and the turtle can only move onto a safe patch. If I have a few patches that are red, how can I 'move' them around as if they were turtles? I currently have this, but it seems to move more than 1 patch at a time occasionally and as a result, some red patches will be destroyed if there are more than one that is red:
if pcolor = red
[ ask patch-at 0 1
[ set pcolor red]
set pcolor black ]
You could ask the neighbor patch (left or right) to be painted red and the actual patch to be painted back to black or whatever the default color is.
For this you'll want to get the actual patch coordinates. Using patch-at asks the patch at 0,1 relative to the whole world.
Currently the landscape I setup in NetLogo includes patches of "typrAgro" in a strip on top and "typeTrop" in a block along the bottom.
to setup
ca
clear-all-plots
clear-output
set typeAgro 1 ;where people will be located
set typeTrop 2 ;where animals will be located
ask patches
[ set habitat typeAgro ]
ask patches with [pycor <= 500] ;world is 600 x 600 pixels
[ set habitat typeTrop]
set AgroForst patches with [ is-Agro? ]
set TropForst patches with [ is-Trop? ]
ask AgroForst
[ set pcolor 75 ]
ask TropForst
[ set pcolor 65 ]
reset-ticks
end
Instead I'd like to create landscapes that have several generic shapes, for example, like those in the image below. In particular, I have no idea how to create the last two shapes (a long linear shape and the random polygon). Any suggestions on how to get started on that would really help. Thanks!
One way I would suggest is creating your map using paint or anything else and define your regions using different colors and then import is as background.
Using
import-pcolors "test.png"
In your setup procedures you can ask different patches with different colors to set their arguments based on your model requirements.