Courses/CS 461/Winter 2006/Rick Strom/Week One/HW1 - Smoke
From CSWiki
< Courses | CS 461 | Winter 2006 | Rick Strom | Week One
;; stromsmoke.nlogo
;; by Rick Strom
;;
;; a 2D fire simulation (smoke version)
;; see Information tab for info on this
patches-own [ heatvalue
next-heatvalue ]
to setup
ca
randomize-bottom-row
end
to go
;; calculate the nextvalues
ask patches [
;; set next-heatvalue to the average of the neighbors - cooling
set next-heatvalue ((
( heatvalue-of patch-at 1 0 +
heatvalue-of patch-at -1 0 +
heatvalue-of patch-at 0 1 +
heatvalue-of patch-at 0 -1
) / 4) - cooling)
if (next-heatvalue < 1) [ set next-heatvalue 0 ]
]
;; reassign the heatvalue for each cell to the
;; next-heatvalue of the cell below it
ask patches [
set heatvalue next-heatvalue-of patch-at 0 -1
set pcolor heatvalue
]
;; re-seed the bottom row
randomize-bottom-row
repeat smoothness [ diffuse pcolor 1 ]
end
to randomize-bottom-row
;; assign random values between 1 and 100 for bottom row
ask patches [
if (pycor = 0 - screen-edge-y ) [
set pcolor random (10)
set heatvalue pcolor
]
]
end

