Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color support to Mathbox surfaces #38

Open
sritchie opened this issue Jun 14, 2023 · 0 comments
Open

Add color support to Mathbox surfaces #38

sritchie opened this issue Jun 14, 2023 · 0 comments

Comments

@sritchie
Copy link
Member

emmy.mathbox.colors:

(ns emmy.mathbox.colors
  "Borrowed from
  https://github.com/ChristopherChudzicki/math3d-react/blob/master/client/src/constants/colors.js"
  (:require ["three" :as three]))

(def colors
  ["#33FF00"
   "#2ecc71"
   "#3498db"
   "#9b59b6"
   "#8e44ad"
   "#2c3e50"
   "#f1c40f"
   "#e67e22"
   "#e74c3c"
   "#808080"])

(def color-maps
  {:rainbow
   {:css "background: linear-gradient(
      to right,
      hsl(360, 100%, 50%),
      hsl(300, 100%, 50%),
      hsl(240, 100%, 50%),
      hsl(180, 100%, 50%),
      hsl(120, 100%, 50%),
      hsl(60, 100%, 50%),
      hsl(0, 100%, 50%)
    )
    "
    :f (fn [frac]
         (let [color (three/Color. 0xffffff)]
           (.setHSL (- 1 frac) 1 0.5)
           [(.-r color) (.-g color) (.-b color)]))}
   :bluered
   {:css "background: linear-gradient(to right, blue, red)"
    :f (fn [frac]
         [frac 0 (- 1 frac) 1])}
   :temperature
   {:css "background: linear-gradient(
      to right,
      hsl(240, 100%, 50%),
      hsl(180, 100%, 50%),
      hsl(120, 100%, 50%),
      hsl(60, 100%, 50%),
      hsl(0, 100%, 50%)
    )
    "
    :f (fn [frac]
         (let [color (three/Color. 0xffffff)]
           (.setHSL (* 0.666 (- 1 frac)) 1 0.5)
           [(.-r color) (.-g color) (.-b color)]))}})

Here is the start of my modificaiton to Surface2D:

(defn true-params-fn [[u-min u-max] [v-min v-max]]
  (let [du (- u-max u-min)
        dv (- v-max v-min)]
    (fn [u v]
      [(+ u-min (* u du))
       (+ v-min (* v dv))])))

[mb/Area
      {:axes (:axes opts)
       :live false
       :items 1
       :channels 4
       :width width
       :height height
       :rangeX (:rangeX opts [0 1])
       :rangeY (:rangeY opts [0 1])
       :expr (let [{:keys [css f]} (:rainbow c/color-maps)
                   true-params (true-params-fn rangeX rangeY)]
               (fn [emit x y i j]
                 (let [[trueU trueV] (true-params x y)]
                   (expr (fn [x y z]
                           )
                         x y i j))
                 (emit x y i j)))}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant