 (ns zajal.brownian
-  (:refer-clojure :exclude [update])
-  (:require [zajal.three :as t :refer [renderer scene camera v3]]
-            [zajal.core :as zajal]))
+  (:require [zajal.three :as t :refer [renderer euler scene camera v3]]
+            [zajal.core :as zajal]
+            [gamma.api :as g]
+            [gamma.program :as p]))
 
 (defn rrand [a b]
   (- (rand (- a b)) a))


;; not bad!

(def step-size 0.02)

(def start
  [(v3 0 0 0)])

(defn update [trail]
  (let [last-point (last trail)]
    (conj trail (v3+ last-point (rand-point step-size)))))

(defn draw [trail]
  [t/basic-scene {:width 600 :height 600}
   [line {:color 0xffffff} trail]])

(defonce sketch (zajal/sketch start update draw))

(defn v3+ [a b]
  (.. a clone (add b)))

(defn apply-angle-axis [v axis angle]
  (.. v clone (applyAxisAngle axis angle)))

(def vertex-position (g/attribute "position" :vec3))

(def vertex-varying (g/varying "pos" :vec3 "highp"))

(def vertex-shader
  {(g/gl-position) (g/vec4 vertex-position 1)
   vertex-varying vertex-position})

(def fragment-shader
  {(g/gl-frag-color) (g/vec4 vertex-varying 1)})

(def rainbow
  (p/program
    {:vertex-shader vertex-shader
     :fragment-shader fragment-shader}))

(def gamma-material
  (js/THREE.RawShaderMaterial.
    #js {:vertexShader (-> rainbow :vertex-shader :glsl)
         :fragmentShader (-> rainbow :fragment-shader :glsl)}))

(defn shaded-line [ps]
  [t/line {:geometry (geometry ps)
           :material gamma-material}])

(defn line [{:keys [color]
             :or {color 0xffffff}}
