Skip to content

Instantly share code, notes, and snippets.

@blad
Last active August 24, 2020 01:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blad/3ccb97219a4cc1883da8eab828b8b95c to your computer and use it in GitHub Desktop.
Save blad/3ccb97219a4cc1883da8eab828b8b95c to your computer and use it in GitHub Desktop.
Ronin: Bucket Implementation
(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))))
@neauoire
Copy link

0__0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment