Last active
August 24, 2020 01:46
-
-
Save blad/3ccb97219a4cc1883da8eab828b8b95c to your computer and use it in GitHub Desktop.
Ronin: Bucket Implementation
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
(resize 100 100) | |
(fill (get-frame) "white") | |
(stroke (rect 23 26 54 49) "black") | |
(def f (get-frame)) | |
(def pls 1) | |
(def mns (sub 0 1)) | |
(defn shift-x (p a) | |
(pos (clamp (add p:x a) 0 f:w) p:y)) | |
(defn shift-y (p a) | |
(pos p:x (clamp (add p:y a) 0 f:h))) | |
(defn around (p) | |
( | |
(shift-x p pls) | |
(shift-x p mns) | |
(shift-y p pls) | |
(shift-y p mns) | |
)) | |
(defn touch (p) (fill (rect p:x p:y 1 1) "red")) | |
(defn matches (p target) | |
(let | |
((candidate (pick (rect p:x p:y 1 1)))) | |
(eq target:rgba candidate:rgba))) | |
(defn bleed (queue target) | |
( | |
(defn apply-color () | |
(let | |
((next (pop queue))) | |
(if | |
(matches next target) | |
( | |
(touch next) | |
(each | |
(around next) | |
(λ (n) (push queue n)))) | |
) | |
) | |
) | |
(defn not-done () (not (eq 0 (len queue)))) | |
(while not-done apply-color) | |
) | |
) | |
(def start (pos 54 55)) | |
(bleed | |
(start) | |
(pick | |
(guide (rect start:x start:y 1 1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0__0