How do I get the white box above the truck? - netlogo

breed [squares square]
breed [trucks truck]
to setup
ca
create-trucks 1 [truck-init]
create-squares 1 [square-init]
end
to square-init
set shape "square"
set size 4
set color white
end
to truck-init
set shape "truck"
set size 9
set color red
end
I get this : http://i.imgur.com/8N1z5g7.png
I want to get the white square above the truck. Any ideas ?

NetLogo draws the breeds in the order they're declared. So right now, squares are drawn, then trucks are drawn on top of them. Thus, you just need to switch the order that breeds are declared, like so:
breed [trucks truck]
breed [squares square]

Related

How can I add real world location to the agent based model in Netlogo?

I have a set of positive COVID-19 cases by district in a state. I want to use agent based modelling to make the infected cases move around the state and count the number of infected, number of healthy and number of immune. I have a set of code which the number of population is random and not based on the location. Tried to watch youtube for the tutorial but could not find one which really helps. the code is as below. I want to insert the map of the state, number of population for each district and number of infected in Netlogo. The codes in Netlogo are as below.
turtles-own [illness]
to setup
clear-all
reset-ticks
create-turtles 200 [
setxy random-xcor random-ycor
set shape "person"
set color pink
set size 1.0
set illness 0
]
ask n-of starting-number-infected turtles [
set color yellow
set shape "X"
set size 1.0
]
end
to go
tick
move
infect
recover
lose-immunity
end
to move
ask turtles [
rt random 360
fd movement
]
end
to infect
ask turtles [
if color = yellow [
ask turtles in-radius infect-distance [
if random-float 200 < infect-chance [
if color = pink [
set color yellow
set shape "X"
]
]
]
]
]
end
to recover
ask turtles [
if color = yellow [
set illness illness + 1
if illness > infectious-period [
set color white
set shape "circle"
set size 1.0
set illness 0
]
]
]
end
to lose-immunity
ask turtles [
if color = white and waning-immunity < random-float 100 [
set color pink
set shape "person"
]
]
end
Our trout model provides an example of using the GIS extension to import a set of polygons that represent the places where agents live. In our case, the polygons are habitat "cells", and the agents are fish; but you could use the same approach to import districts and keep track of which people are in which district.
Our model does not represent where a fish is within a polygon, but only which polygon they are in. We use a separate breed of agent called "cells" that contain the variables of the polygon. Each NetLogo patch has a variable "patches-cell" that says which cell it belongs to.
The model is here: https://ecomodel.humboldt.edu/instream-7-and-insalmo-7
(look for inSTREAM7.3). Look at the procedure build-cells.
Steve R.

Why color doesn't changed for the turtles?

I'm quite new to NetLogo and I want to use the below code to create a world of green and red circles, but the below code doesn't work with the color as it is only grey? any advice?
to create_turtles
ca
ask patches [ sprout 1 ]
ask turtles [ set shape "circle" set color green]
end
I just tried your code and it works just fine except it just create all green turtles (circles). If you want it red and green, I suggest you add some piece of code in the ask turtles command and may I suggest you to use the indentation style as well (usually NetLogo will do it automatically):
to create_turtles
ca
ask patches [ sprout 1 ]
ask turtles
[
set shape "circle"
set color green
let chooser random 2
ifelse chooser = 0
[ set color green ]
[ set color red ]
]
The let procedure is a local variable assigner and we let the value a random number of 0 and 1 (two numbers, hence the random 2, and primitive random always include 0 as first number).
In that example we ask the circles to randomly choose a number between 0 and 1. If it chooses 0 then it will set it color to green, otherwise red.
You can explore more about those primitives in the NetLogo Dictionary.

Calculate Distance b/w Two Point in Netlogo

I have have done map representation on Netlogo Using GIS Extension and loaded the data using .shp dataset. Now I want to get distance b.w two points.
Is there any way to get the distance b.w two stations which I represented in blue color. The distance needs to be calculated by the roads (eg. red and white lines)
extensions [GIS]
globals [
boundaries-gis1
Roads-gis2
Fire_Stations-gis3
waypoints
Buildings-gis4
]
to load
clear-all
set Boundaries-gis1 gis:load-dataset "Boundaries.shp"
set Roads-gis2 gis:load-dataset "Roads.shp"
set Fire_Stations-gis3 gis:load-dataset "Fire_Stations.shp"
set Buildings-gis4 gis:load-dataset "Buildings.shp"
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of Boundaries-gis1)
(gis:envelope-of Roads-gis2)
(gis:envelope-of Fire_Stations-gis3)
(gis:envelope-of Buildings-gis4)
)
gis:set-drawing-color red
gis:draw Boundaries-gis1 2
gis:set-drawing-color white
gis:draw Roads-gis2 1
gis:set-drawing-color blue
gis:draw Fire_Stations-gis3 5
gis:set-drawing-color pink
gis:draw Buildings-gis4 2
end

Adding obstacles and targets from shapefile in netlogo

I am new to NetLogo, so my apologies in advance if that question is very stupid. I would like to create an Agent-Based Model where animals move around in a complex terrain looking for water sources. Movement should be downhill, constrained by steep slopes (>25°) and targets should be lakes. I am using a real-world example from GIS data for this, and I have already managed to setup a world containing an ASCII elevation grid, a shapefile containing lines that represent slopes steeper 25degrees and a shapefile containing areas representing lakes. I have created animals (cows) and found a code line telling them to move downhill. Now, I would like to tell them
a) to avoid slopes >25° by using the slope shapefiles as obstacles and
b) to go to the lakes by using the lake shapfiles as targets
Can someone help me how to code this?
Many thanks in advance!
Here is the code I have put together so far
breed [ cows cow ]
extensions [ gis ]
patches-own [ elevation ]
globals [
slope-dataset
lake-dataset
elevation-dataset
]
to setup-terrain
clear-all
reset-ticks
set slope-dataset gis:load-dataset "FILENAME.shp" ;;extent of GIS datasets is N42.3-43.4 and W120.0-121.1
set lake-dataset gis:load-dataset "FILENAME.shp"
set elevation-dataset gis:load-dataset "FILENAME.asc"
gis:set-world-envelope gis:envelope-of slope-dataset
gis:set-world-envelope gis:envelope-of lake-dataset
gis:set-world-envelope gis:envelope-of elevation-dataset
end
to display-slopes
gis:set-drawing-color red
gis:draw slope-dataset 0.5
end
to display-lakes
gis:set-drawing-color blue
gis:draw lake-dataset 2
end
to display-elevation-in-patches
gis:apply-raster elevation-dataset elevation
let min-elevation gis:minimum-of elevation-dataset
let max-elevation gis:maximum-of elevation-dataset
ask patches
[ ; note the use of the "<= 0 or >= 0" technique to filter out
; "not a number" values, as discussed in the documentation.
if (elevation <= 0) or (elevation >= 0)
[ set pcolor scale-color black elevation min-elevation max-elevation ] ]
end
to setup-cows
set-default-shape cows "cow"
create-cows 100 [
setxy random-pxcor random-pycor
set size 1
set color white
]
end
to move
move-to patch-here ;; go to patch center
let p min-one-of neighbors [elevation]
if [elevation] of p < elevation [
face p
move-to p ;; makes cows move to the next lower elevation patch, if no lower
elevetion is present, cow doesn't move
]
end
to go
ask cows [
move
]
end
Thanks Seth, I have found the solution using the gis:intersects? primitive you suggested:
to display-slopes
ask patches gis:intersecting slope-dataset
[ set pcolor red ]
end
to go
ask cows
[fd 1
avoid-ostacles]
tick
end
to avoid-obstacles
ask cows [
if [pcolor] of patch-ahead 1 = red
[rt 90 fd 1]]
end
This way I can color the patches in red that intersect with the shapefile containing the slope vector dataset and then ask the cows to avoid and move around red colored patches.
Thanks again!

Change the color of the turtle on the move

I'm writing a program about traffic in roundabouts. I have 3 colors for 3 different directions car was red car turn right, go straight green car, sky turn left. because there is one lane for turning right should not I want to change the car red car blue sky or other AU to the cars that did not go right anymore?
What function should I use to change the color of the car?
This will not be correct because I can't work out exactly what you need from the question, but you need to use the with statement to identify the correct cars. Here is something that is close to what I think you want:
to ...
...
let to-be-red cars with [ (heading = 0 or heading = 180)
and distancexy 0 0 < 30
and ycor < -11 ]
ask to-be-red [ set color red ]
end