Appendix A:
StarLogo programming code
globals [aps pnm dr winddist pnmx pnmy apsx
apsy drx dry
diff windx windy]
patches-own [newso2 so2]
to setup
clearall
; draw shiprock
draw-map
ask-patches
[setso2 0]
;set the so2
production rate
setaps 96
setpnm 41
; set the
diffusion rate
setdiff 5
; set the wind
distribution
; using the
unbiased distribution for now
set windx [0
1
1 1 0 -1 -1 -1]
set windy [1
1
0 -1 -1 -1 0 1]
end
to draw-map
setapsx 3
setapsy -3
setpnmx 7
setpnmy 3
create-turtles-and-do
1 [ setxy 0 0 setc blue
]; shiprock
create-turtles-and-do
1 [ setxy pnmx pnmy setc
brown ]; pnm
create-turtles-and-do
1 [ setxy apsx apsy setc
brown ]; aps
end
; new plant
to newplant
create-turtles-and-do 1 [ setxy drx dry
setc brown ];
dr
setdrx 0
setdry
-15
ask-patches
[setso2 0]
setdr 14
setdiff
5
end
to go
; pump
out
so2 from plants
ask-patch-at
apsx apsy [ set so2 ( aps + so2) ]
ask-patch-at
pnmx pnmy [ set so2 ( pnm + so2 ) ]
ask-patch-at
drx dry [ set so2 ( dr + so2 ) ]
; difuse so2
down the gradient
; but don't
wrap around the screen edges
ask-patches-with [ xcor = screen-half-width ] [setso2 0]
ask-patches-with [ ycor = screen-half-height ] [setso2 0]
ask-patches-with [ xcor = (0 - screen-half-width) ] [ setso2 0]
ask-patches-with [ ycor = (0 - screen-half-height) ] [ setso2 0]
diffuse so2
(diff / 100)
; let wind
move theso2 down wind
; choose-wind
-use the sliders
; this code
simply moves all of the so2 down wind
;ask-patches
[setnewso2 so2-towards winddir windspd]
; ask-patches
[setso2 newso2]
blow-wind
item
(1 + winddir) windx item (1 + winddir) windy (windspd / 50)
;scale the
patch color to grey
ask-patches [
scale-pc brown so2 0 50]
end
to blow-wind :x :y :fraction
ask-patches
[setnewso2 0]
ask-patches
[setnewso2 (newso2 + :fraction * (so2-at :x :y))]
ask-patches
[setnewso2 (newso2 + (1 - :fraction) * so2)]
ask-patches
[setso2 newso2]
end
to choose-wind
; this is an
even distribution of directions and speeds
; with no bias
to preserve direction or speed
set winddir
45
* (random 8)
set windspd 5
* (random 8)
end