Created
January 16, 2009 17:06
-
-
Save swannodette/48011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn diffuse [grid diff-ratio dt] | |
(let [a (float (* dt diff-ratio grid-size grid-size)) | |
a4-1 (float (+ 1 (* 4 a))) | |
grid #^floats (deref grid) | |
diffused-grid #^floats (make-grid) | |
grid-size (int grid-size) | |
line-length (int (+ grid-size 2))] | |
(dotimes [n 20] | |
(dotimes [y grid-size] | |
(let [line-offset (* (inc y) line-length)] | |
(loop [x (int 1) | |
c (int (+ x line-offset))] | |
(aset diffused-grid c | |
(/ (+ (aget grid c) | |
(* a | |
(+ (+ (aget diffused-grid | |
(unchecked-dec c)) | |
(aget diffused-grid | |
(unchecked-inc c))) | |
(+ (aget diffused-grid | |
(unchecked-subtract c line-length)) | |
(aget diffused-grid | |
(unchecked-add c line-length)))))) | |
a4-1)) | |
(when (< x grid-size) | |
(recur (unchecked-inc x) | |
(unchecked-inc c))))))) | |
diffused-grid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment