Using scale-color in netlogo - netlogo

I am using scale-color color number range1 range2
But I am not clear about range1 and range2. What do actually they mean? and how to determine the value for range1 and range2 ?

I believe those are the lower and upper limits of the numbers you might want converted into colors. The number preceding those should be in that range! A number lower than that range will be set to the darkest share (black) , and a number higher than that range will be displayed as the lightest shade ( white ).
You can just open a new model and type some commands into the command line and see what you get. Here's some to try:
ask patches [ set pcolor scale-color red 25 0 50]
ask patches [ set pcolor scale-color red 25 20 50]
ask patches [ set pcolor scale-color red 25 0 30]
ask patches [ set pcolor scale-color red 400 0 30]
ask patches [ set pcolor scale-color red 0 25 30]
Your comment asks how scale-color is used in the climate-change model which has the following code:
to setup-world
set sky-top max-pycor - 5
set earth-top 0
ask patches [ ;; set colors for the different sections of the world
if pycor > sky-top [ ;; space
set pcolor scale-color white pycor 22 15
]
if pycor <= sky-top and pycor > earth-top [ ;; sky
set pcolor scale-color blue pycor -20 20
]
if pycor < earth-top
[ set pcolor red + 3 ] ;; earth
if pycor = earth-top ;; earth surface
[ update-albedo ]
]
end
ok so let's look those statements one at a time.
First:
if pycor > sky-top [ ;; space
set pcolor scale-color white pycor 22 15
]
Looking at the User Dictionary
The template is "scale-color color number range1 range2 "
So range1=22 and range2=15.
The Dictionary says
If range1 is less than range2, then the larger the number, the lighter
the shade of color. But if range2 is less than range1, the color
scaling is inverted.
We have the case where range2 is less than range1, so "the color scaling is inverted", ie the larger the number, the darker the shade of color.
Therefore as pycor increases from 15 to 22 the resulting color will start at white, get darker and darker, and finally become black. That's exactly what we see in the model after hitting setup. As we move upwards above the blue sky, where it transitions to white, outer-space starts at white, gets darker and darker, and finally becomes black.
How about this:
if pycor <= sky-top and pycor > earth-top [ ;; sky
set pcolor scale-color blue pycor -20 20
The model viewport has max-pycor set to 22, so sky-top defined as ( max-pycor - 5 ) would be 17. In other words this is going to look up colors for pycor ranging from 1 to 17.
In this case range1 is less than range2, so if pycor increased from -20 to 20, the resulting color would start at pycor = -20 with black, increase through darker shades till at pycor=0 we have pure blue, and then lighter tints of blue, and end up when pycor=20 at white.
That's exactly what we see in the model between the top of the earth and the top of the blue sky. Except, in the model, earth-top is at pycor=0, so only the numbers from earth-top + 1 (1) to sky-top (17) are ever looked up, and so the resulting reported colors range from blue up through nearly white.
That's exactly what the sky does as pycor goes up from the earth to the sky-top -- it starts at blue and changes gradually to white.
I hope this helps!

Related

NetLogo Battle Simulation: Placing soldiers in between specific coordinates?

I'm new to NetLogo and I'm unsure of how to place 300 spartans in a narrow row. Let's say an area of 2x5 patches, turtles overlapping one another. I have tried using sprout, this achieved the specific coordinate requirements but the turtles are only one per patch.. Here is some code I have.
ask patches with [pxcor > 0 and pycor > -2 and pycor < 2]
[ sprout 1 [ set color red ] ]
or
to setup-spartans
create-spartans 300
set-default-shape turtles "person"
ask spartans
[ setxy random-xcor -3 ;; makes only a single row and goes across entire screen
;; (I need it to be in a specific area)
set heading 180
set color red ]
end
How about something like this?
create-spartans 300 [
set xcor -2 + random-float 5
set ycor -1 + random-float 2
]

Imported Patch colors not working correctly in NetLogo

I've been trying to get my turtles to 'bounce' off a wall using Netlogo.
I've imported a png file that has the colors of the different surfaces (walls, interface, liquid, heater eventually there will be a few more). I used MSPaint and the colormap from netlogo color chart to create my shapes (a purple square, with brown on the side borders, red border on the bottom and blue border on the top)
What I'm trying to do is have the turtles start on the liquid patches and move in straight lines until they bump into a surface (different colored wall). If they bump into a wall, they should 'bounce' off in a random direction, if they hit the heater, their temperature should go increase and they should also bounce off of the heater surface. If they bump into the interface and their temperature is above 100, they should move through the interface and then move around above the interface (basically teleport up a few pixels).
The issue I'm having is that the turtles move around and they appear to be bouncing off the walls just fine, but they seem to be oblivious to the colors of the heater and the interface. I'm sure I'm missing something basic or obvious, but I've been struggling for three days on this same quirk. Any help would be greatly appreciated.
Here is the code I have right now:
(in this code I have it set to just 'teleport' through the interface regardless of the temperature of the water)
globals[ liquid-color heater-color wall-color reflection-color air-color interface-color
liquid heater wall reflection air interface]
breed [h2o water]
to setup
clear-turtles
reset-ticks
clear-all-plots
import-pcolors "boilermap.png"
set liquid-color 115
set heater-color 19
set wall-color 35
set interface-color 105
setup-patches
create-molecules
end
to setup-patches
set heater patches with [pcolor = heater-color]
set heater-color 19
ask heater [set pcolor 19]
set interface patches with [pcolor = interface-color]
set interface-color 105
ask interface [set pcolor 105]
set liquid patches with [pcolor = liquid-color]
set liquid-color 115
ask liquid [set pcolor 115]
set wall patches with [pcolor = wall-color]
set wall-color 35
ask wall [set pcolor 35]
end
to create-molecules
create-h2o (totalmoles * h20number / 100)[
set shape "circle"
set color black
set size 2
set temperature 20
setxy random xcor random ycor
move-to one-of patches with [pcolor = liquid-color]
]
to go
ask h2o [
(ifelse
pcolor = liquid-color[fd 1 ];ifblock
pcolor = heater-color [set temperature temperature + 5]
pcolor = interface-color [set ycor ycor + 100] ;just trying to get them to jump here, regardless of their temperature
;elseblock
[ bk 1
rt random 180]
)]
end
Diesel, you have a great start on this! I put some code below that answers your questions.
By the way, the title on your question doesn't really match what your actual problem was: imported patch colors not working correctly
I suspect the reason your code ignores the heater and interface is that they imported as pcolors that don't match the ones you expected. I added a verify-colors command that checks to see if the imported colors are correct. I also added an option to generate a new boiler image you can work with in case importing still causes more problems.
Also, I notice you are adding 100 to ycor when your molecule hits the interface. It's possible this moves the molecule entirely up out of view, which could be confusing, as the default view is only 32 units high. I changed the 100 to 5 to keep the molecule in view.
I cleaned up a few more things and confirmed the model ran successfully. The handling of correct bouncing off walls and off the heater was not addressed -- that's your job!
Here's the things I tweaked in your code:
;;
;; added h2o-own section so molecules each have a temperature
;; added a user-choice of whether to import the boilermap.png or create a new one here
;; if importing, verify the colors exactly match the valid colors
;; added "make-drawing" and "verify-colors" sections at the end
;; moved reset-ticks to the end of setup, its usual location
;; added ticks to the end of the go section !!
;; added set-aircolor grey ( it wasn't defined )
;; cleaned out unneeded commands from the setup-patches section. You already have the
pcolors imported, so you don't need to set them again.
;; added "set label temperature" to the create-molecules section as well as to the place
;; where temperature is increased at the heater, so each molecule shows its current temperature
I tested it with interface variables h2o-number =100 and total-moles either 1 or 5 and speed set to very slow. It works!
globals[ liquid-color heater-color wall-color reflection-color air-color interface-color
liquid heater wall reflection air interface]
breed [h2o water]
h2o-own [
temperature
]
to setup
clear-turtles
clear-all-plots
set liquid-color 115
set heater-color 19
set wall-color 35
set interface-color 105
set air-color grey
if-else user-yes-or-no? "import boilermap.png?"
[
import-pcolors "boilermap.png"
verify-colors ;; check the command section for counts of pcolors
]
[
make-drawing ;; just make a new image of a boiler
]
setup-patches
create-molecules
reset-ticks ;; usually, do this as the last step in setup
end
to setup-patches
set heater patches with [pcolor = heater-color]
set interface patches with [pcolor = interface-color]
set liquid patches with [pcolor = liquid-color]
set wall patches with [pcolor = wall-color]
end
to create-molecules
no-display
create-h2o (totalmoles * h20number / 100)[
set shape "circle"
set color black
set size 2
set temperature 20
setxy random xcor random ycor
move-to one-of patches with [pcolor = liquid-color]
set label temperature
]
display
end
to go
ask h2o [
(ifelse
pcolor = liquid-color[fd 1 ]
pcolor = heater-color [ set temperature temperature + 5 set label temperature set heading 0 forward 1]
pcolor = interface-color [set ycor ycor + 5 forward 1 ]
pcolor = wall-color and pxcor < 0 [set heading 135 forward 1]
pcolor = wall-color and pxcor > 0 [set heading 220 forward 1]
[ bk 1
rt random 180]
)]
tick ; DONT FORGET THIS !!
end
;; ========================== new utility functions ===
to make-drawing
no-display
ask patches with [ pycor > 1] [ set pcolor air-color]
ask patches with [ pycor < 1] [set pcolor liquid-color]
ask patches with [ abs pycor <= 1] [ set pcolor interface-color]
ask patches with [ pycor < (min-pycor + 4)] [ set pcolor heater-color]
ask patches with [ pxcor > (max-pxcor - 2)] [ set pcolor wall-color]
ask patches with [ pxcor < (min-pxcor + 2)] [ set pcolor wall-color]
ask patches with [ pycor > (max-pycor - 2)] [ set pcolor wall-color]
ask patches with [ pycor < (min-pycor + 2)] [ set pcolor wall-color]
display
end
to verify-colors ;; see what we imported
let good-colors (list
liquid-color
heater-color
wall-color
interface-color
air-color )
let good-count count patches with [member? pcolor good-colors]
let bad-count count patches - good-count
type "good patch count " type good-count type ", bad patch count: " print bad-count
if bad-count > 0 [ if "no" = user-yes-or-no? " bad patch colors, should I continue?" [stop] ]
end

How to change from Random placement of turtles to fixed placement

Grasses (green leaf) are randomly placed across the world with setxy random-xcor random-ycor. What I want is for its position to be fixed (e.g., every leaf will be placed 10 units apart per line). Can anyone helped me how to alter my setxy, or is there any other way. Thank you very much
Maybe the mod modulus operator will do the trick for you. For example:
to setup
ca
resize-world 0 50 0 50
ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
sprout 1 [
set shape "leaf"
set color green
]
]
reset-ticks
end

Netlogo - set background shape

How can I add a static shape to the model`s world ?
I know that in order to set an image I can do import-pcolors "Image.png"
Can I do the same with the shape?
Currently in order to add such a shape I do:
ask patches with [((pxcor > 4) and (pxcor < 9) and
(pycor > -11) and (pycor < 5))]
[ set pcolor white
set plabel-color black
ask turtle 0 [
setxy 8 2
set color blue
set shape "circle"]
]

Wall agents in netlogo

I am trying to simulate a room with opening door. Instead of using patches I wish to use agents.
The earlier approach I followed was first creating a box with a gap and then distributing agents on it.
But it didn't seem give the results.
(Netlogo Sprouting turtles at regular intervals
Netlogo Sprouting turtles spaced at less than one patch)
Above is roughly sketched diagram.
Note:
An easier to do it would to sprout turtles at each patch. But I don't require so. Instead I wish to make turtles small and sprout one more than at a patch.
Thanks.
Question: distribute turtles along the sides of a rectangle (with a gap as shown in fig) and distribution can be varied depending upon the desired density of turtles.
The following does the job in case someone in future faces such a issue:
set breadth-patches patches with[(pycor > (-(breadth)) and pycor < breadth and pxcor = lengthrec) or(pycor > (-(breadth)) and pycor < breadth and pxcor = (-(lengthrec))) ]
set length-patches patches with[(pxcor > (-(lengthrec)) and pxcor < lengthrec and pycor = (-(breadth - 1))) or (pxcor > (-(lengthrec)) and pxcor < lengthrec and pycor = (breadth - 1))]
set gap-patches patches with [pxcor > (gap * (-1)) and pxcor < gap and pycor =(breadth - 1)]
set length-patches length-patches with [not member? self gap-patches]
ask breadth-patches[
sprout-walls 1[set color 2
set size 0.5 set heading 180 fd 0.25
if-else(pxcor < 0)[set heading 90][set heading 270] fd 0.25]
sprout-walls 1[set color 2
set size 0.5 set heading 360 fd 0.25
if-else(pxcor < 0)[set heading 90][set heading 270] fd 0.25]
]
ask length-patches[
sprout-walls 1[set color 2
set size 0.5 set heading 90 fd 0.25
if-else(pycor < 0)[set heading 180][set heading 0] fd 0.25
]
sprout-walls 1[set color 2
set size 0.5 set heading 270 fd 0.25
if-else(pycor < 0)[set heading 180][set heading 0] fd 0.25
]
]
end