Trying to let a flood appear with every tick and make it disappear after every tick as well. Meanwhile, the tick counter should go on.
The flood appears this way:
to water_rise
ask patches [ ; saturates cell
if is-DEM < 800[
set cell-storage cell-storage + fill-rate
]
]
ask patches [
if any? neighbors4 with [ any? turtles-here ] [
set cell-storage cell-storage + fill-rate
]
]
ask patches [
if cell-storage > 0 [
if cell-storage > 5 [
set cell-storage 5
if not any? turtles-here [
sprout 1 [
set color blue
set size 10
set shape "circle"
]
]
]
set pcolor cell-storage + 82
]
]
end
Currently trying to figure out how to let the flood disappear after/or within this the tick, so that it can reoccur in the next one. I´m not aiming to reset the tick counter, it should reach 200.
Tried resetting the ticks, but only to manage resetting everything.
Any ideas ?
Thank you very much in adavance
Cheers
You can simply use the display primitive to update the view without waiting for the tick counter to advance.
I am not familiar with your whole model but here's a conceptual example that may help:
to water_rise
...
end
to go
repeat 100 [
water-rise
display
]
tick
end
This code would execute your water-rise procedure 100 times, update the view with new patch colors after each execution, and only increase the tick counter by 1 after the repeat loop is done.
Here is the link to NetLogo Dictionary entry about the display primitive:
http://ccl.northwestern.edu/netlogo/docs/dictionary.html#display
Note: due to its design, NetLogoWeb does not support the display primitive. So, you need to use the desktop version.
Related
In the simulation I am working on, I have red turtles.
I want them to be yellow at the beginning, then turn orange after 10 ticks, then red after 10 other ticks.
How can I do so ?
to ignite
ask fires [
if count neighbors > 0 [
ask one-of neighbors with [pcolor = white or pcolor = green ]
[
if count fires-here < 6 [
sprout-fires 3
[ set color red set size 3 ]
]
]
]
]
end
Note that you have tick in your setup procedure as provided. That needs to be in your go procedure. setup is for everything when the simulation starts, and go is what happens each time step. The command tick advances the counter for the time steps, and the reporter ticks reads the time step counter.
If you are going to change a turtle's colour based on how long it's been alive, the first thing you need to do is to have the turtle know when it is 'born', so create a variable for that and store the current value of ticks in that variable during the creation.
fires-own
[ state ; you have this already
birth-tick ; this is the new one
]
Change this:
sprout-fires 3
[ set color red set size 3 set state "live"]
to this (note that spacing does not matter to NetLogo, but helps with readability)
sprout-fires 3
[ set color red
set size 3
set state "live"
set birth-tick ticks
]
So that creates the birth time. Now, within your go procedure (which you don't show), you want all the turtles that are 10 ticks old to change colour. One way is:
ask fires with [ birth-tick = ticks - 10 ] [ set color orange ]
Based on the “sheep eat grass” model. The patches are changing color with the agents move. I want to check if a patch has remain a centain color for a while (such as 5 ticks). If a patch has stayed in a centain color for a centain times without any change it will turn into black.
I try to use countup but it didn’t work. I need a accumulated state. Thanks a lot
If pcolor=green[
Ifelse countup>=5[
Set pcolor black
Set countup 0]
[set countup countup+1]]
Can you give a little more detail as to what is going wrong with the code you've shown? For example, with this setup:
patches-own [ time-spent-green ]
to setup
ca
crt 3
reset-ticks
end
Something very similar to your example works fine for me:
to go
ask turtles [
rt random 61 - 30
fd 1
ask patch-here [
set pcolor green
]
]
ask patches with [ pcolor = green ] [
ifelse time-spent-green >= 5 [
set pcolor black
set time-spent-green 0
] [
set time-spent-green time-spent-green + 1
]
]
tick
end
Where the patches stay green for 5 ticks then turn back to black.
newbie in netlogo here. I'm simulating a flood model using cellular-automata. It's just a simple one - cell should be filled (change color) or sprout if water > elevation.
For a dummy code, I'm trying to do it this way:
to go
ask patches with [pcolor != blue] ;remove ocean
water_rise
tick
end
to water_rise ; saturates cell
if not any? turtles [
ask patch x-breach y-breach [ ;;; This will be the breach patch, will start to fill at first tick, a specific location in my map
set cell-storage elevation * fill-rate
]
]
ask patches [
;;; This has a patch check if any neighbors have sprouted.
;;; If any have, that patch starts to fill.
if any? neighbors4 with [ any? turtles-here ] [
set cell-storage elevation * fill-rate
let minv min [ cell-storage ] of patches
let maxv max [ cell-storage ] of patches
set pcolor scale-color green cell-storage 0 5 ;idea is to have a graduated color depending on fill stage
]
]
;;; Once all patches have had a chance this tick to fill,
;;; see if any are "full"
ask patches [
if cell-storage > elevation [
;; If the patch gets "full" and they have not already sprouted,
if not any? turtles-here [
sprout 1 [
set color yellow
set size 1
set shape "square"
]
]
]
]
end
Thanks in advance!
BTW, I'm working on a DEM re: elevation values.
I set fill-rate as a slider with 0.3 for now.
-Nands
I played around with this a little and it seems to me like you want your starting patch to fill up, and once it hits its maximum value, to start flooding into other cells that repeat the process. I think the main problem is that in your water-rise, you have are asking all patches with elevation greater than -9999 to first call the starting-point procedure and then also to sprout a turtle if they have any neighbors with elevation is less than cell-storage. It appears that all patches satisfy that condition, so all patches will sprout a turtle.
It may work better to rework your flow of logic, so that filling up your breach patch is independent of other patches. Something like:
to water_rise ; saturates cell
if not any? turtles [
ask patch 0 0 [ ;;; This would be your breach patch, will start to fill at first tick
set cell-storage cell-storage + fill-rate
]
]
ask patches [
;;; This has a patch check if any neighbors have sprouted.
;;; If any have, that patch starts to fill.
if any? neighbors4 with [ any? turtles-here ] [
set cell-storage cell-storage + fill-rate
]
]
;;; Once all patches have had a chance this tick to fill,
;;; see if any are "full"
ask patches [
if cell-storage > 0 [
if cell-storage > 5 [
set cell-storage 5
;; If the patch gets "full" and they have not already sprouted, sprout 1
if not any? turtles-here [
sprout 1 [
set color yellow
set size 0.5
set shape "circle"
]
]
]
set pcolor cell-storage + 82
]
]
end
Full toy model with variables and setup here.
Obviously, you would need to modify your starting patch (I used 0 0 for convenience and simplicity). Additionally, I included fill-rate as a way to slow the rate of filling as more and more patches begin getting filled up.
i'm trying to make an archaeological model, in which hunters are making paintings in shelters, depending on their quality.
breed [shelters shelter]
breed [hunters hunter]
shelters-own [quality paintings]
The value of each shelter quality is set in the setup (with a slider for the actual number of shelters).
create-shelters number-shelters [set quality random 100]
The action of painting-or-not is then defined by random against the quality of each shelter:
to make-painting
ask shelters [
if any? hunters-on patch-here [
if random 100 < quality [set paintings paintings + 1]
]
]
end
Now, I would like to complexify it a bit more: the quality wouldn't be defined by the shelter itself (and thus be the same for every hunter), but by the hunters: each of them would attribute a different quality for each shelter. The action of painting-or-not would still be a test against random, but with this new variable defined by each individual hunter...
But I can't find a way to code it down properly.
Does anyone have a suggestion?
I think I got it right. Basically, I had every hunter to create a matrix filled with random numbers. The size is 33x33, so it goes all over the world (had to set it to start in a corner, or it gets negative coordinates).
create-hunters number-hunters [
set color white
set size 1
setxy random-xcor random-ycor
set hunter-matrix matrix:make-constant 33 33 random 10
]
ask n-of number-shelters patches [
sprout-shelters 1 [
set color one-of base-colors
set size 1
set xpatch xcor set ypatch ycor
]
Then, when they would reach a shelter, the value corresponding to that patch location would be extracted and used to paint-or-not.
ask patches [
ask hunters-here [set quality matrix:get hunter-matrix xpatch ypatch]
let paintings-here sum [paintings] of shelters-here
if any? hunters-here and any? shelters-here [
if random 10 < quality [
ask shelters-here [
set paintings paintings + 1]
]
]
]
I'm still not completely sure it actually does what I think it's doing, tho.
layout intersections with traffic lights. I want the car to stop when the red lights and the lights go xanh.thi what I should use for car algorithm can recognize the color of the lights
I have used light layout algorithm as follows
to draw-stop-light
ifelse stop-light = "north"
[
ask patch -7 12 [set pcolor green ]
ask patch 10 10 [ set pcolor red ]
ask patch -10 -10 [ set pcolor red ]
]
[
ask patch -7 12 [ set pcolor red ]
ask patch 10 10 [ set pcolor green ]
ask patch -10 -10 [ set pcolor green ]
]
end
This is really a question better suited to the NetLogo users group here than Stack Overflow since you are asking how to program a poorly defined specification. For example, the users group may be able to point you to a similar model. Stack Overflow is really about fixing specific problems with your code. However, here's something to get you started until the question gets deleted.
Break down what you want to happen into very small steps and then code each step. The steps will be something like:
When the car gets near the intersection, check to see what colour the traffic light is
If the light is red, remember to stop at the intersection
Stop at the intersection if required
If at the intersection, wait until the light turns green then go
Do NOT try to write the whole thing. Instead, write one bit at a time and test is to see if it works. Here is some approximate code for the first bit:
ask cars
[ ifelse heading = 180 and ycor > 20 and ycor < 25 and not stop-flag
[ if [ pcolor of patch -7 12 ] = red [ set stop-flag true ] ]
[ ... (cars from other directions)
]
ask cars
[ forward speed
if stop-flag and ... (on intersection patches)
[ ... (move backwards to be outside the intersection)
set stop-flag false
]
]
patch-right-and-ahead (http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-lr-and-ahead) could be useful here. Perhaps something like:
if [pcolor] of patch-right-and-ahead 90 1 = red
[ set speed 0 ]