Skip to content

Instantly share code, notes, and snippets.

@dimovich
Created June 28, 2018 09:46
Show Gist options
  • Save dimovich/bc52b77e2280ac56a2ed68a987d5ec57 to your computer and use it in GitHub Desktop.
Save dimovich/bc52b77e2280ac56a2ed68a987d5ec57 to your computer and use it in GitHub Desktop.
(require '[thi.ng.color.core :as col]))
(defn cosine-coeficients
"amp = (R1-R2) / 2; dc offset = R1-amp; freq = -0.5"
([h1 h2]
(let [coerce #(col/as-rgba (col/hex->int %))
colors (->> [(coerce h1) (coerce h2)]
(map #(select-keys % [:r :g :b])))
[c1 _] colors
amp (->> colors
(apply
mapv (fn [[_ v1] [_ v2]]
(* 0.5 (- v1 v2)))))
offset (->> amp
(mapv (fn [[_ v1] a]
(- v1 a))
c1))]
[offset amp
[-0.500 -0.500 -0.500]
[0.000 0.000 0.000]])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment