Camo-Evolution customizes our NetLogo framework.
Here's a screen shot:
Turtles that have a color close to the background have a better chance of surviving and reproducing than do highly visible turtles.
The offspring of two survivors has a color between the color of its parents.
The user can control the color of the background. Shifting the color shifts the population.
The delta slider determines the visibility threshold.
Here's a link: Camo-Evolution
Recall that in NetLogo colors are represented by numbers from 0 to 140.
Colors ending in 5 are the named colors: brown, red, yellow, etc.
NetLogo has a predefined list called base-colors:
[5 15 25 35 45 55 65 75 85 95 105 115 125 135]
In Camo-Evolution every turtle has an age attribute.
Initially, every turtle has one of the base colors:
to init-turtle
set color one-of base-colors
set age 1
set xcor random-xcor
set ycor random-ycor
set label"*"
end
A slider defines a global variable called patch-color:
Every time patches are initialized or updated, they set their pcolor attribute to patch-color:
set pcolor patcch-color
Here's the basic turtle update procedure:
to update-turtle
move
hide
if age mod 10 = 0 [reproduce]
ifelse age <= 100
[
set age age + 1
]
[
die
]
end
After moving a few steps in a random direction, a turtle attempts to hide from predators. Success is a combination of visibility and luck:
to hide
let luck random 100
let visibility abs (color -
patch-color)
ifelse (visibility < delta)
[
??? ; die if luck is small
]
[
??? ; die unless luck is big
]
end
Turtles can be created by the observer:
crt N [init newborns]
by a patch:
sprout N [init newborns]
or by another turtle:
hatch N [init newborns]
In each case N is the number of turtles born. The optional block that follows will be executed by each newborn.
Every 10 ticks lucky turtles get to mate:
to reproduce
let luck random 100
let mate one-of turtles in-radius 3
if mate != nobody and 30 < luck
[
???
]
end
A turtle draws a lucky number and randomly selects a nearby mate.
If a mate is found, and if luck is high, then a new turtle is hatched. If luck is very high, the newborn will have a random color (this represents random mutation). Otherwise, the color will be between the colors of each parent:
; assume t1 and t2 are the parent turtles
to-report compute-child-color [t1 t2]
let p1 position [color] of t1
base-colors
let p2 position [color] of t2
base-colors
let p3 round ((p1 + p2) / 2)
report item p3 base-colors
end
Here's the moment of birth:
hatch 1
[
print "whoopee"
set color child-color
set heading random 360
set label "*"
]
There are 14 named colors. Ideally, our plot should have 14 pens named p5, p15, ..., p135. The color of each pen should be the corresponding named color.
Note that color 25 represents orange.
Here is the update-plot procedure:
to update-plot
set-current-plot-pen "p5"
plot avg-with-color 5
set-current-plot-pen "p15"
plot avg-with-color 15
set-current-plot-pen "p25"
plot avg-with-color 25
set-current-plot-pen
"p35"
plot avg-with-color 35
set-current-plot-pen "p45"
plot avg-with-color 45
;etc.
end
This procedure must be called at the bottom of the framework's update procedure.
Note: Using 14 pens could get very messy. For my demo I only used four pens.
Here is how the averages are computed:
to-report avg-with-color [clr]
let total count turtles
ifelse total = 0
[
report 0
]
[
report 100 * (count turtles with
[color = clr]) / total
]
end