update folds to 4.0.0

This commit is contained in:
Anish Lakhwara 2023-01-03 15:16:29 +10:00
parent 831296227b
commit 3124a71111
3 changed files with 46 additions and 20 deletions

BIN
folds/out/hyperbolic-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View file

@ -4,4 +4,4 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.1"]
[quil "3.1.0"]])
[quil "4.0.0-SNAPSHOT"]])

View file

@ -3,21 +3,21 @@
[quil.middleware :as m]))
(defn settings []
(q/smooth 8))
(q/smooth))
(def y (atom -3))
(reset! y 0)
(def keep-going (atom true))
(def x1 -3)
(def y1 -3)
(def y (atom y1))
(def x2 3)
(def y2 3)
(defn setup []
(q/background 0 0 0)
; Set frame rate to 30 frames per second.
(q/frame-rate 30)
; Set color mode to HSB (HSV) instead of default RGB.
(q/color-mode :hsb)
; (q/color-mode :hsb)
; circle color and position.
{:color 0
:angle 0
@ -25,44 +25,70 @@
(defn update-state [state]
; Update sketch state by changing circle color and position.
{:color (mod (+ (:color state) 0.7) 255)
{:color (mod (+ (:color state) 10.7) 255)
:angle (+ (:angle state) 0.1)
:step (:step state)})
(defn sinusodial [v amount]
(println v)
(def test-vecs
[[2.98798 2.6571]
[0.00153 0.05489]
[-1.548 -2.0157]])
(defn test-func
[func]
(mapv #(func % x2) test-vecs))
(defn hyperbolic
"doesn't handle negative numbers?"
[v amount]
(let [[x y] v
mag (q/sqrt (reduce + (mapv * v)))
r (+ mag (q/exp -10))
theta (q/atan2 x y)]
[(* amount (/ (q/sin theta) r)) (* amount (* (q/cos theta) r))]))
(comment
(test-func hyperbolic))
(defn sinusodial
[v amount]
(->> v
(mapv (partial q/sin))
(mapv * [amount amount])))
(mapv (partial * amount))))
(comment
(test-func sinusodial))
(defn draw-variation
[v state]
(let [[xx yy] (->> v
; (mapv #(sinusodial % 3))
(let [[xx yy] (->> (hyperbolic v x2)
; #(sinusodial % x2)
(mapv (partial * (q/random-gaussian) 0.003))
(mapv #(q/map-range % x1 x2 20 (- (q/width) 20))))]
(q/point xx yy)))
(defn draw-state
[state]
; (q/background 0 0 0)
(let [color (:color state)
step (:step state)]
; Set color.
(q/fill color 255 255)
(q/stroke color 255 255)
(q/fill 255 255 255)
(q/stroke color 255 155)
(q/stroke-weight 0.2)
(if @keep-going
(do
(doseq [x (range x1 x2 step)
y (range y1 y2 step)]
(draw-variation [x y] state))
(reset! keep-going false)))
(q/ellipse 50 50 15 15)))
(doseq [_ (range 12)]
(doseq [x (range x1 x2 step)]
(draw-variation [x @y] state))
(swap! y + step)
(if (> @y y2)
(reset! keep-going false)))))))
; (q/ellipse 50 50 15 15)))
(q/defsketch folds
:title "Folding"
:size [500 500]
:size [520 520]
; setup function called only once, during sketch initialization.
:setup setup
; update-state is called on each iteration before draw-state.