I'm creating a code that is supposed to make a certain number of turtles have a status of 1 and the rest have a status of 0, the number is calculated using slider inputs from the interface. I've been trying to make the program use n-of but it turns more than the desired number of turtles into the 1 variety (the turtles are set to status 0 from before).
code below (switch for single is to change to only one turtle and tumble switch is for modelling tumbling and running):
to spawn
ifelse (single = false )
[create-turtles N [
set color black
set xcor 0
set ycor 0
set heading random-float 360
set status 0
if (tumble = true)
[
print (N * p1 / (p1 + p2))
ask n-of (N * p1 / (p1 + p2)) turtles [set status 1 set color red]]
]
]
[create-turtles 1 [
set color black
set xcor 0
set ycor 0
set heading random-float 360
pendown
]]
end
The problem is in your placement of the ask n-of statement. The code is the brackets after create-turtles N is executed for each turtle that is created, so each of the N created turtles is in turn asking n-of ... turtles to set status to 1. You will get many more turned turtles than you want. Moving the if (tumble ... block out of the create-turtles block should lead to its being executed only once, after all N turtles are created.
to spawn
ifelse (single = false ) [
create-turtles N [
set color black
set xcor 0
set ycor 0
set heading random-float 360
set status 0
]
if (tumble = true) [
print (N * p1 / (p1 + p2))
ask n-of (N * p1 / (p1 + p2)) turtles [set status 1 set color red]
]
]
[create-turtles 1 [
set color black
set xcor 0
set ycor 0
set heading random-float 360
pendown
]
]
end
Related
With this model I need the code for the first year (tick = 0) to be different to the remaining 4. I've run the code below and the first tick runs ok, it then ticks and stops - none of the tick = 1 code seems to be running.
globals [num_agents difference year leader_test ]
breed [tasks task]
breed [managers manager ]
tasks-own [requirement leadership matched ]
managers-own [ability wealth matched requirement task_leader]
to setup
clear-all
set num_years 5
set tolerance 5
set num_agents 100
create-tasks num_agents [
set shape "box"
set leadership one-of [10 20 30 40 50 60 70 80 90 100]
ifelse who < 50 [setxy 0 who set color blue][setxy 45 (who - 50) set color blue]
set heading 90
set requirement who + 100
set matched 0
]
create-managers num_agents [
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270
set ability (who - num_agents + 100)
set wealth 0 set matched 0
]
reset-ticks
end
to go
;;first year -different to remaining
ifelse ticks < 1 [
ask managers with [matched = 0]
[show ticks
move-to one-of tasks with [matched = 0]
fd -1
set requirement [requirement] of one-of tasks-on patch-ahead 1
set task_leader [leadership] of one-of tasks-on patch-ahead 1
set difference abs(requirement - ability)
set matched 1
set wealth (requirement)
show wealth
show task_leader
ask tasks-on patch-ahead 1 [set matched 1 set shape "arrow" set heading 0]
if difference > tolerance [set color red ask tasks-on patch-ahead 1 [set shape "circle" ] ]]
]
; years 2 - num_years
[
ask managers [
if ability > (requirement + tolerance) [
ask tasks-on patch-ahead 1 [set matched 0 set shape "box" ]
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270 set matched 0
]
]
ask managers with [matched = 1]
[ set leader_test random 100
if ability < (requirement - tolerance) [
if leader_test <= task_leader
[;;leader should make correct decision and fire manager
ask tasks-on patch-ahead 1 [set matched 0 set shape "butterfly" ]
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270 set matched 0]
]
]
]
ask managers with [matched = 0]
[move-to one-of tasks with [matched = 0]
fd -1
set matched 1]
ask managers with [matched = 1][
set requirement [requirement] of one-of tasks-on patch-ahead 1
set task_leader [leadership] of one-of tasks-on patch-ahead 1
set difference abs(requirement - ability)
set wealth (wealth + requirement)
ask tasks-on patch-ahead 1 [set matched 1 set shape "arrow" set heading 0]
if difference > tolerance [set color red ask tasks-on patch-ahead 1 [set shape "circle" ]
]
]
ifelse ticks > (num_years ) [
stop] [tick ]
I have had problems with ticks and stop before - there is obviously something I'm not getting.
Per LeirsW
It runs just fine for me. You are using a forever button right?
I am working with the daisyworld model and am planning to add a predator to the model which will eat the daisies (this is for a class project). I have successfully added the predators (brown rabbits eat the white daisies, grey rabbits eat the black daisies). But in order for them to eat the daisies, their coordinates have to line up perfectly causing very little "eating" to occur. Is there a way for me to generate rabbits with random xy cor but be generated in the exact center of the pixel?
globals [
max-age ;; maximum age that all daisies live to
global-temperature ;; the average temperature of the patches in the world
num-blacks ;; the number of black daisies
num-whites ;; the number of white daisies
scenario-phase ;; interval counter used to keep track of what portion of scenario is currently occurring
]
breed [daisies daisy]
breed [brown-rabbits brown-rabbit]
breed [grey-rabbits grey-rabbit]
patches-own [temperature] ;; local temperature at this location
daisies-own [
age ;; age of the daisy
albedo ;; fraction (0-1) of energy absorbed as heat from sunlight
daisy-black ;; boolean if daisy is black
]
brown-rabbits-own
[energy]
grey-rabbits-own
[energy]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
set-default-shape daisies "flower"
ask patches [ set pcolor gray ]
set max-age 25
set global-temperature 0
if (scenario = "ramp-up-ramp-down" ) [ set solar-luminosity 0.8 ]
if (scenario = "low solar luminosity" ) [ set solar-luminosity 0.6 ]
if (scenario = "our solar luminosity" ) [ set solar-luminosity 1.0 ]
if (scenario = "high solar luminosity") [ set solar-luminosity 1.4 ]
seed-blacks-randomly
seed-whites-randomly
ask daisies [set age random max-age]
ask patches [calc-temperature]
set global-temperature (mean [temperature] of patches)
update-display
;reset-ticks
create-grey-rabbits grey-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color grey
set energy random (2 * grey-rabbit-gain-from-food)
]
create-brown-rabbits brown-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color brown
set energy random (2 * brown-rabbit-gain-from-food)
]
reset-ticks
end
to seed-blacks-randomly
ask n-of round ((start-%-blacks * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-black] ]
ask daisies [set daisy-black true]
end
to seed-whites-randomly
ask n-of floor ((start-%-whites * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-white] ]
ask daisies [set daisy-black false]
end
;to daisy-black
; ifelse color = 0
; [daisy-black true]
; [daisy-black false]
;end
;ask daisies if color = 0 [set daisy-black true]
;ask daisies if color = 9.9 [set daisy-black false]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
ask grey-rabbits [
move
set energy energy - 1
eat-black-daisies
death
reproduce-grey-rabbits
]
ask brown-rabbits [
move
set energy energy - 1
eat-white-daisies
death
reproduce-brown-rabbits
]
ask patches [calc-temperature]
diffuse temperature .5
ask daisies [check-survivability]
set global-temperature (mean [temperature] of patches)
update-display
tick
if scenario = "ramp-up-ramp-down" [
if ticks > 200 and ticks <= 400 [
set solar-luminosity precision (solar-luminosity + 0.005) 4
]
if ticks > 600 and ticks <= 850 [
set solar-luminosity precision (solar-luminosity - 0.0025) 4
]
]
if scenario = "low solar luminosity" [ set solar-luminosity 0.6 ]
if scenario = "our solar luminosity" [ set solar-luminosity 1.0 ]
if scenario = "high solar luminosity" [ set solar-luminosity 1.4 ]
end
to move
rt random 20
lt random 20
fd 1
end
to eat-black-daisies ;grey rabbits eat black daisies
ask grey-rabbits
[if any? daisies-here with [daisy-black = true]
[let prey one-of daisies-here; with [daisy-black = true]
if prey != nobody
[ask prey [die]
set energy energy + grey-rabbit-gain-from-food]
]
]
end
to eat-white-daisies ;brown rabbits eat white daisies
; ask brown-rabbits
; ;[if any? daisies-here with [daisy-black = false]
; patch-here
; [let prey one-of daisies-here with [daisy-black = false]
; if prey != nobody
; [ask prey [die]
; set energy energy + brown-rabbit-gain-from-food]
; ]
; ;]
end
to reproduce-grey-rabbits
if random-float 100 < grey-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to reproduce-brown-rabbits
if random-float 100 < brown-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to death
if energy < 0 [die]
end
to set-as-black ;; turtle procedure
set color black
set albedo albedo-of-blacks
set age 0
set size 0.6
end
to set-as-white ;; turtle procedure
set color white
set albedo albedo-of-whites
set age 0
set size 0.6
end
to check-survivability ;; turtle procedure
let seed-threshold 0
let not-empty-spaces nobody
let seeding-place nobody
set age (age + 1)
ifelse age < max-age
[
set seed-threshold ((0.1457 * temperature) - (0.0032 * (temperature ^ 2)) - 0.6443)
;; This equation may look complex, but it is just a parabola.
;; This parabola has a peak value of 1 -- the maximum growth factor possible at an optimum
;; temperature of 22.5 degrees C
;; -- and drops to zero at local temperatures of 5 degrees C and 40 degrees C. [the x-intercepts]
;; Thus, growth of new daisies can only occur within this temperature range,
;; with decreasing probability of growth new daisies closer to the x-intercepts of the parabolas
;; remember, however, that this probability calculation is based on the local temperature.
if (random-float 1.0 < seed-threshold) [
set seeding-place one-of neighbors with [not any? daisies-here]
if (seeding-place != nobody)
[
if (color = white)
[
ask seeding-place [sprout-daisies 1 [set-as-white] ]
]
if (color = black)
[
ask seeding-place [sprout-daisies 1 [set-as-black] ]
]
]
]
]
[die]
end
to calc-temperature ;; patch procedure
let absorbed-luminosity 0
let local-heating 0
ifelse not any? daisies-here
[ ;; the percentage of absorbed energy is calculated (1 - albedo-of-surface) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
set absorbed-luminosity ((1 - albedo-of-surface) * solar-luminosity)
]
[
;; the percentage of absorbed energy is calculated (1 - albedo) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
ask one-of daisies-here
[set absorbed-luminosity ((1 - albedo) * solar-luminosity)]
]
;; local-heating is calculated as logarithmic function of solar-luminosity
;; where a absorbed-luminosity of 1 yields a local-heating of 80 degrees C
;; and an absorbed-luminosity of .5 yields a local-heating of approximately 30 C
;; and a absorbed-luminosity of 0.01 yields a local-heating of approximately -273 C
ifelse absorbed-luminosity > 0
[set local-heating 72 * ln absorbed-luminosity + 80]
[set local-heating 80]
set temperature ((temperature + local-heating) / 2)
;; set the temperature at this patch to be the average of the current temperature and the local-heating effect
end
to paint-daisies ;; daisy painting procedure which uses the mouse location draw daisies when the mouse button is down
if mouse-down?
[
ask patch mouse-xcor mouse-ycor [
ifelse not any? daisies-here
[
if paint-daisies-as = "add black"
[sprout-daisies 1 [set-as-black]]
if paint-daisies-as = "add white"
[sprout-daisies 1 [set-as-white]]
]
[
if paint-daisies-as = "remove"
[ask daisies-here [die]]
]
display ;; update view
]
]
end
to update-display
ifelse (show-temp-map? = true)
[ ask patches [set pcolor scale-color red temperature -50 110] ] ;; scale color of patches to the local temperature
[ ask patches [set pcolor grey] ]
ifelse (show-daisies? = true)
[ ask daisies [set hidden? false] ]
[ ask daisies [set hidden? true] ]
end
; Copyright 2006 Uri Wilensky.
; See Info tab for full copyright and license.
Instead of checking whether 2 turtles are exactly on the same spot, I would use patch-here to see if they are on the same patch.
https://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-here
I want my turtles to hatch (= make one more turtle) when they cross a specific line. I have tried the command ifelse?, and I can get it to work on a simple model, when my turtles randomly wanders: If they move to a patch on the left side (xcor < 0) they die, if they make a move to a patch with xcor > 0 they hatch 1.
But I want the proces to be linked to witch patch they come from. If they stand on a patch with xcor < 0 and moves to another patch with xcor < 0 they shall die - but if they change xcor from negative to positive - they should multiply (= hatch 1).
My problem is: Is it possible to write a code-string that "remembers" the turtles position one tick before and use it to either let the turtle die og multiply?
{
to setup
clear-all
create-turtles 20
ask turtles [set size 2
set heading random 45 ;; turtle is now facing northeast
setxy random-xcor random-ycor
set color white
set shape "person"]
end
to go
ask turtles
[ rt random 360 ; turns in a random direction
fd 4 ;; all turtles move forward one step
rt random 180 ;; ...and turn a random amount
fd 4
lt random 180
]
ask turtles
[ifelse pxcor > 0
[hatch random 2]
[die]]
end }
You can use a turtle variable to give each turtle a memory.
turtles-own
[
old-xcor
]
Just before the turtle moves, assign ‘xcor‘ to that variable.
To move-turtle
Set old-xcor xcor
< Your movement code >
if old-xcor < 0
[ Ifelse xcor < 0
[ Die ]
[ Hatch 1 ]
]
End
I created a rectangular turtle grid using a total of 1000 turtles.
let in-shape patches with [ pxcor >= -50 and pxcor <= 50 and pycor >= -5 and pycor <= 5 ]
ask in-shape [ sprout 1 ]
Now I need to create a sort of gradient, that will give a sense of distance to my turtle swarm. Given a "seed" with value 0, it emits a message with its value 0 in a certain talk_radius.
The turtles inside this talk_radius compute their distance to the seed. If the distance is less than a fixed value (called gradient_distance) the turtle will assume 1 as gradient_value, emitting a message with its value.
The other turtles do the same. So everyone will take the value x + 1, where x is the lowest value of the turtle within the gradient_distance, as shown in the picture
This is the relative algorithm in pseudo code:
loop
if gradient seed = TRUE then // check if robot is designated as gradient source
gradient value(self) = 0
else
gradient value(self) = GRADIENT MAX
for all neighbors n do
if measured distance(n) < G then // G represents the gradient-distance and GRADIENT MAX is infinity
if gradient value(n) < gradient value(self) then
gradient value(self) = gradient value(n)
gradient value(self) = gradient value(self) + 1
transmit gradient value(self)
And that's my implementation in netlogo:
globals [talk_radius gradient_max gradient_distance]
turtles-own [gradient_seed gradient_value]
to setup
ca
resize-world -60 60 -20 20
crt 1000
let in-shape patches with [ pxcor >= -50 and pxcor <= 50 and pycor >= -5 and pycor <= 5 ]
ask in-shape [ sprout 1 ]
set talk_radius 4
set gradient_max 100000
set gradient_distance 1
ask turtles
[set shape "circle"]
ask turtles-on patch -50 5
[set gradient_seed true]
end
to gradient-formation
while [true]
[
ask turtles
[
ifelse (gradient_seed = true)
[
set gradient_value 0
]
[
set gradient_value gradient_max
set color scale-color green gradient_value 0 120
ask (other turtles) in-radius talk_radius with [distance myself <= gradient_distance] ;; i consider all the turtle in talk_radius having the right gradient_distance
[
let a ([gradient_value] of self) ;; "of self" is not necessary but helped me for a better comprehension
if (a < ([gradient_value] of myself))
[
ask myself [set gradient_value a]
]
]
set gradient_value (gradient_value + 1)
]
set color scale-color green gradient_value 0 120
]
]
end
I used a scale-color in order to have a feedback of what i have done, as you can see in the image.
And now the problem: instead of let a ([gradient_value] of self), i tried set a ([gradient_value] of self) adding a to the turtle variable (I added a in the turtle-own list on top).
I thought the result would have been the same, but instead i got a constantly increasing gradient_value for every turtle as you can see in the image(the color white denotes a very high gradient_value).
Why this difference? Thank you in advance and sorry for the long question.
EDITED EXTENSIVELY in response to discussion that refined the problem
First, I would like to start with a simpler version of the code. I believe this is exactly the same as yours without the while[true]. I removed the extra 1000 turtles you are creating, and separated the ifelse on whether a seed into two separate ask statements, for clarity. I also moved the colouring until after the value calculation is complete.
globals [talk_radius gradient_max gradient_distance]
turtles-own [gradient_seed? gradient_value]
to setup
clear-all
resize-world -60 60 -20 20
let in-shape patches with [ pxcor >= -50 and pxcor <= 50 and pycor >= -5 and pycor <= 5 ]
ask in-shape
[ sprout 1
[ set shape "circle"
set gradient_seed? false
]
]
set talk_radius 4
set gradient_max 100000
set gradient_distance 1
repeat 10 [ gradient-formation ]
end
to gradient-formation
ask turtles-on patch -50 5
[ set gradient_seed? true
set gradient_value 0
]
ask turtles with [not gradient_seed?]
[ set gradient_value gradient_max
ask (other turtles) in-radius talk_radius with [distance myself <= gradient_distance]
[ let my-gradval ([gradient_value] of self)
if my-gradval < [gradient_value] of myself
[ ask myself [set gradient_value my-gradval]
]
]
set gradient_value (gradient_value + 1)
]
ask turtles [set color scale-color green gradient_value 0 120 ]
end
There is a conceptual issue here. Until a turtle has its gradient_value calculated, it is 0. This means a large number of turtles will have a 0 turtle nearby and then have their own gradient_value as 1. It does not produce a colour gradient. To get around this, you need to run the gradient-formation several times. The approach in your code of while [true] introduces an infinite loop. Instead, you can repeat an arbitrary number of times (10 in the code above).
The problem with let versus set + turtles-won is that the set with turtles-own creates 1000 copies of gradient_value - one for each turtle. The let version creates a (temporary) global variable that all turtles access. So when you use set, you are setting it for that turtle, not as a general access number. I think what is happening is that the line set gradient_value my-gradval is accessing the wrong turtle's copy of my-gradval.
But, from the discussion, the purpose of the code that is causing the problem is to find a local minimum. There is a much more direct way of doing that.
to gradient-formation
ask turtles-on patch -50 5
[ set gradient_seed? true
set gradient_value 0
]
ask turtles with [not gradient_seed?]
[ set gradient_value 1 + min [gradient_value] of
other turtles in-radius min (list talk_radius gradient_distance)
]
ask turtles [set color scale-color green gradient_value 0 120 ]
end
ADDED a minimum working example to show the differences.
This is the let (global variable) version
turtles-own [testval]
to testme
clear-all
create-turtles 500
[ setxy random-xcor random-ycor
set color blue
set testval 1 + random 10
]
ask one-of turtles
[ set color red
inspect self
type "testval of asking turtle is " print testval
ask turtles-on neighbors
[ set color yellow
let my-testval [testval] of self ;; creates a temp global variable
type "my-testval is " print my-testval
if my-testval < [testval] of myself
[ ask myself
[ set testval my-testval ;; copies the global variable value
]
]
]
]
end
This is the set (turtle attribute) version
turtles-own [testval my-testval]
to testme
clear-all
create-turtles 500
[ setxy random-xcor random-ycor
set color blue
set testval 1 + random 10
]
ask one-of turtles
[ set color red
inspect self
type "testval of asking turtle is " print testval
ask turtles-on neighbors
[ set color yellow
set my-testval [testval] of self
type "my-testval is " print my-testval
if my-testval < [testval] of myself
[ ask myself
[ set testval my-testval ;; copies value from one attribute to other
]
]
]
]
end
How can I accomplish the following in the code below:
patches change color reflective of their distance from the row "min-pycor"
For example, colors alternate from yellow to red and then to black (signifying death).
But this should take into account that the production of yellow patches > red > black.
turtles-own
[
stem? ;; true for stem cells, false for transitory cells
age ;; age of cell. changes color with age
metastatic? ;; false for progeny of stem cell 0, true for progeny of stem cell 1
]
globals
[
cell-count
]
to setup
clear-all
set-default-shape turtles "square"
ask patches[
if pycor = min-pycor [
ifelse random 10 <= 2
[set pcolor white]
[sprout 1 [set shape "square" set color blue] ]
]
]
evaluate-params
reset-ticks
end
to go
ask patches with [pcolor = yellow]
[if count neighbors with [pcolor = black] > 0
[ask one-of neighbors with [pcolor = black][set pcolor yellow]
]
]
ask patches with [pcolor = white]
[if count neighbors with [pcolor = black] > 0
[ask one-of neighbors with [pcolor = black][set pcolor yellow]
]
]
tick
end
;;transitional cells move and hatch more. Turtle proc.
to move-transitional-cells
if (not stem?)
[
set color ( red + 0.25 * age )
fd 1
if (age < 6)
[
hatch 1
[ ;amplification
rt random-float 360
fd 1
]
]
]
end
to mitosis ;; turtle proc. - stem cells only
if stem?
[
hatch 1
[
fd 1
set color red
set stem? false
ifelse (who = 1)
[ set age 16 ]
[ set age 0 ]
]
]
end
to death ;; turtle proc.
if (not stem?) and (not metastatic?) and (age > 20)
[ die ]
if (not stem?) and metastatic? and (age > 4)
[ die ]
end
to evaluate-params
set cell-count count turtles ;cell count
if (cell-count <= 0)
[ stop ]
end
to kill-original-stem-cell
ask turtle 0
[ die ]
end
to kill-moving-stem-cell
ask turtle 1
[ die ]
end
to kill-transitory-cells
ask turtles with [ age < 10 and not stem? ]
[ die ]
end
You seem to have two conflicting requirements, the color change based on proximity in your code, and the color change based on PYCOR that you ask about.
Ignoring the code for a moment, we can set color based on PYCOR in many ways. For example, we can create bands of color, we can create dithered interminglings of color, or we can create a "smooth" transition between colors.
The first is easy. We can use an IFELSE structure. This example creates even bands, but you can change the "divide" variables to create bands of any height.
let color1 red
let color2 yellow
let color3 black
let divide1 (min-pycor + world-height * 0.33)
let divide2 (min-pycor + world-height * 0.66)
ask patches
[ ifelse pycor < divide1 [ set pcolor color1 ][
ifelse pycor < divide2 [ set pcolor color2 ][
set pcolor color3
]]
]
We can also do it in a mathy way. This example creates even bands.
let colors [ red yellow black ]
let bands length colors
let band-height floor ( world-height / bands + .5 )
;; pycor - min-pycor shifts the range from 0 to world-height
ask patches [ set pcolor item ( floor ( ( pycor - min-pycor ) / band-height ) ) colors ]
We can create dithered bands by introducing a random element to the pycor. we also have to add some tests to keep the random numbers in range.
let colors [ red yellow black ]
let bands length colors
let band-height floor (world-height / bands + .5)
let dither band-height * .5 ;; adjust this to change dithery-ness
ask patches
[ let py pycor - min-pycor + dither - random-float ( dither * 2 )
;; you might want to really study the above line to fully grok what's happening there
if py < 0 [ set py 0 ]
if py > world-height [ set py world-height ]
set pcolor item ( floor ( py / band-height ) ) colors
]
Graduated (gradiant) bands are tougher, because the NetLogo color space doesn't do gradual shifts in hue, only tint and shade, so there's really no way to get from red to yellow that way. So we would have to use RGB (three value list)colors, instead of NetLogo (single value) colors. And that's beyond what I'm willing to type out at the moment, so there you go--left as an exersize.