Courses/CS 461/Winter 2006/Darren Iwaki/461/Week 4
From CSWiki
< Courses | CS 461 | Winter 2006 | Darren Iwaki
Didn't have a lot of time to work on this, this week but was working with the PaintedDesert Model in an attempt to get rid of the grains in the middle of piles more efficiently 1. tried to use the mouse cursor to delete those grain. seems like im missing something. 2. figure out a way to may for the termites to communciate with one another to form discrete piles really incomplete code. i hope to update this later on in the week.
globals [ clock ] turtles-own [ chip? ] patches-own [ turtle-color]
to setup
ca
ask patches
[ if random-float 100 < density
[ set pcolor ((random colors) * 10) + 5 ] ]
cct number
[
set color white
set chip? false
setxy random-float screen-size-x
random-float screen-size-y ]
do-plots
end
to go
set clock clock + 1
if mouse-down?
[
ask patch-at mouse-xcor mouse-ycor
[ set pcolor black ]
]
find-chip ;; find a wood chip and pick it up
find-new-pile ;; find another wood chip
find-empty-spot ;; find a place to put down wood chip
do-plots
end
to find-chip ;; turtle procedure
if (chip? = false)
[
ifelse (pcolor != black) ;; if i dont have a chip and im on a new chip
[
set color pcolor ;; let the turtle carry 'pcolor'
set pcolor black ;; set the patch to black
set chip? true ;; turtle now has a chip
;; turtle is now of the color
get-away
stop ]
[
wiggle
find-chip ]
]
end
to find-new-pile ;; turtle procedure
if (pcolor = color) [ stop ] fd 10 wiggle find-new-pile
end
to find-empty-spot
if pcolor = black [ set pcolor color ;; put down wood chip in patch set chip? false set color white fd 1 stop ] rt random-float 360 fd 1 find-empty-spot
end
to get-away
rt random-float 360 back 10 if (pcolor = black) [ stop ] ;; exit this procedure if not on a pile get-away
end
to wiggle
fd 1 rt (random-float 50 - random-float 50)
end
to do-plots
if (clock mod 100 = 0) [ set-current-plot "Termites Carrying Chips" set-current-plot-pen "default" plot count turtles with [color != white] ]
end

