Courses/CS 461/Winter 2006/Rick Strom/Week One/HW1 - Water
From CSWiki
< Courses | CS 461 | Winter 2006 | Rick Strom | Week One
;; stromwater.nlogo
;; by Rick Strom
;;
;; a 2D water simulation (ripples)
;; see Information tab for info on this
patches-own [ height
prev-height
next-height ]
globals [ x y ]
to setup
ca
ask patches [
set height 0
set next-height 0
set prev-height 0
set pcolor height + 93
]
end
to go
if continuous-drops [ add-drop ]
ask patches [
; calculate the next-height values
set next-height (
(((
height-of patch-at 0 1 +
height-of patch-at 1 0 +
height-of patch-at 0 -1 +
height-of patch-at -1 0
) / 2) - prev-height) * damping
)
]
ask patches [
; copy over next-height values
set prev-height height
set height next-height
set pcolor height + 93
]
end
to add-drop
; we just randomly choose a patch and set its value to 100 (white-blue)
set x random(2 * screen-edge-x) - screen-edge-x
set y random(2 * screen-edge-y) - screen-edge-y
set height-of patch-at x y 20
set pcolor-of patch-at x y height-of patch-at x y + 93
end

