diff options
author | equa <equaa@protonmail.com> | 2021-04-19 20:39:21 -0500 |
---|---|---|
committer | equa <equaa@protonmail.com> | 2021-04-19 20:39:21 -0500 |
commit | 00af64d4e503dd82abf4657ec6fd44b0a418adb2 (patch) | |
tree | 4e864337769f5ddd792db95be3bc761159748af4 /lib/cells.fnl | |
parent | ca870dab91daee38b8d55ac6d2f2b4fd6959c6ac (diff) |
cool bullets
Diffstat (limited to 'lib/cells.fnl')
-rw-r--r-- | lib/cells.fnl | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/cells.fnl b/lib/cells.fnl index 3a43010..e415f21 100644 --- a/lib/cells.fnl +++ b/lib/cells.fnl @@ -17,18 +17,26 @@ (set x (+ x 1)))) x) +(fn neighbors< [f threshold] + (var x 0) + ;; nnn this could be faster maybe + (for [k 1 8] + (when (< (cell.aliveness (f (. neighbors k))) threshold) + (set x (+ x 1)))) + x) + (local life {cell.init (fn [self] (setmetatable {} self)) cell.birth (fn [self get] - (if (= (neighbors> get 0) 3) + (if (= (neighbors> get 0.5) 3) self nil)) cell.update (fn [self get] - (let [n (neighbors> get 0)] + (let [n (neighbors> get 0.5)] (if (or (= n 3) (= n 2)) self @@ -65,12 +73,12 @@ (local boom {cell.init - (fn [self] - (setmetatable {:life 1} self)) + (fn [self x] + (setmetatable {:life (or x 1)} self)) cell.birth (fn [self get] (if (and (> self.life 0.08) - (> (neighbors> get (* (if (> self.life 0.9) 0.3 0.1) (math.random 7))) 0)) + (> (neighbors< get (* (if (> self.life 0.9) -0.3 -0.1) (math.random 7))) 0)) (do (setmetatable {:life (* self.life 0.8)} (getmetatable self))) nil)) @@ -80,7 +88,7 @@ (setmetatable {:life (* self.life (+ 0.5 (* (math.random 5) 0.1)))} (getmetatable self)) nil)) cell.aliveness - #$.life + #(- $.life) cell.color #[(+ 0.4 (* 0.6 $.life)) (math.max 0 (- 0.8 (* 0.9 (- 1 $.life)))) |