<commit_before>(ns org.playasophy.wonderdome.mode.rainbow
  (:require
    [org.playasophy.wonderdome.geometry.sphere :as sphere]
    [org.playasophy.wonderdome.mode.core :as mode]
    [org.playasophy.wonderdome.util.color :as color]))


(def ^:private ^:const move-rate
  "Rate at which the angles change in radians per millisecond."
  0.0005)


(defrecord RainbowMode
  [polar azimuth scale speed offset]

  mode/Mode

  (update
    [this event]
    (case [(:type event) (:button event)]
      [:time/tick nil]
      (let [elapsed (or (:elapsed event) 0.0)
            offset' (+ offset (* (/ speed 1000) elapsed))
            offset' (if (> offset' 1.0) (- offset' 1.0) offset')]
        (assoc this :offset offset'))

      ; TODO: add controls for adjusting speed and scale
      ; TODO: add reset button

      [:button/repeat :x-axis]
      (let [delta (* (or (:value event) 0)
                     (or (:elapsed event) 0)
                     move-rate)]
        (assoc this :azimuth
          (sphere/wrap-angle (+ azimuth delta))))

      [:button/repeat :y-axis]
      (let [delta (* (or (:value event) 0)
                     (or (:elapsed event) 0)
                     move-rate)]
        (assoc this :polar
          (sphere/wrap-angle (+ polar delta))))

      ; default
      this))


  (render
    [this pixel]
    (let [angle (sphere/angle-offset (:sphere pixel) [0 polar azimuth])
          index (* scale (- angle offset))]
      (color/rainbow index))))


(defn rainbow
  "Creates a new rainbow color-cycling mode."
  []
  (RainbowMode. 0.0 0.0 1.0 1.0 0.0))
<commit_msg>Change rainbow mode controls to speed/scale.<commit_after>(ns org.playasophy.wonderdome.mode.rainbow
  (:require
    [org.playasophy.wonderdome.mode.core :as mode]
    [org.playasophy.wonderdome.util.color :as color]
    [org.playasophy.wonderdome.util.control :as control]))


(defrecord RainbowMode
  [scale speed offset]

  mode/Mode

  (update
    [this event]
    (case [(:type event) (:button event)]
      [:time/tick nil]
      (let [elapsed (or (:elapsed event) 0.0)
            offset' (+ offset (* (/ speed 1000) elapsed))
            offset' (if (> offset' 1.0) (- offset' 1.0) offset')]
        (assoc this :offset offset'))

      [:button/repeat :x-axis]
      (assoc this :scale
             (control/adjust scale event
                             :rate 0.5
                             :min-val 0.1
                             :max-val 5.0))

      [:button/repeat :y-axis]
      (assoc this :speed
             (control/adjust speed event
                             :rate 0.5
                             :min-val -3.0
                             :max-val  3.0))

      ; default
      this))


  (render
    [this pixel]
    (let [[_ angle _] (:sphere pixel)
          index (- (* scale angle) offset)]
      (color/rainbow index))))


(defn rainbow
  "Creates a new rainbow color-cycling mode."
  []
  (RainbowMode. 1.0 1.0 0.0))

{'fraction_non_alphanumeric': 0.1336952833389888, 'fraction_numerical': 0.019681031557516118, 'mean_word_length': 1.8704965920155794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142131', 'n_tokens_mistral': 1030, 'n_tokens_neox': 911, 'n_words': 260}