update folds to 4.0.0
This commit is contained in:
parent
831296227b
commit
3124a71111
BIN
folds/out/hyperbolic-1.png
Normal file
BIN
folds/out/hyperbolic-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
|
@ -4,4 +4,4 @@
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "Eclipse Public License"
|
||||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||||
:dependencies [[org.clojure/clojure "1.10.1"]
|
:dependencies [[org.clojure/clojure "1.10.1"]
|
||||||
[quil "3.1.0"]])
|
[quil "4.0.0-SNAPSHOT"]])
|
||||||
|
|
|
@ -3,21 +3,21 @@
|
||||||
[quil.middleware :as m]))
|
[quil.middleware :as m]))
|
||||||
|
|
||||||
(defn settings []
|
(defn settings []
|
||||||
(q/smooth 8))
|
(q/smooth))
|
||||||
|
|
||||||
(def y (atom -3))
|
|
||||||
(reset! y 0)
|
|
||||||
(def keep-going (atom true))
|
(def keep-going (atom true))
|
||||||
(def x1 -3)
|
(def x1 -3)
|
||||||
(def y1 -3)
|
(def y1 -3)
|
||||||
|
(def y (atom y1))
|
||||||
(def x2 3)
|
(def x2 3)
|
||||||
(def y2 3)
|
(def y2 3)
|
||||||
|
|
||||||
(defn setup []
|
(defn setup []
|
||||||
|
(q/background 0 0 0)
|
||||||
; Set frame rate to 30 frames per second.
|
; Set frame rate to 30 frames per second.
|
||||||
(q/frame-rate 30)
|
(q/frame-rate 30)
|
||||||
; Set color mode to HSB (HSV) instead of default RGB.
|
; Set color mode to HSB (HSV) instead of default RGB.
|
||||||
(q/color-mode :hsb)
|
; (q/color-mode :hsb)
|
||||||
; circle color and position.
|
; circle color and position.
|
||||||
{:color 0
|
{:color 0
|
||||||
:angle 0
|
:angle 0
|
||||||
|
@ -25,44 +25,70 @@
|
||||||
|
|
||||||
(defn update-state [state]
|
(defn update-state [state]
|
||||||
; Update sketch state by changing circle color and position.
|
; 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)
|
:angle (+ (:angle state) 0.1)
|
||||||
:step (:step state)})
|
:step (:step state)})
|
||||||
|
|
||||||
(defn sinusodial [v amount]
|
(def test-vecs
|
||||||
(println v)
|
[[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
|
(->> v
|
||||||
(mapv (partial q/sin))
|
(mapv (partial q/sin))
|
||||||
(mapv * [amount amount])))
|
(mapv (partial * amount))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(test-func sinusodial))
|
||||||
|
|
||||||
(defn draw-variation
|
(defn draw-variation
|
||||||
[v state]
|
[v state]
|
||||||
(let [[xx yy] (->> v
|
(let [[xx yy] (->> (hyperbolic v x2)
|
||||||
; (mapv #(sinusodial % 3))
|
; #(sinusodial % x2)
|
||||||
|
(mapv (partial * (q/random-gaussian) 0.003))
|
||||||
(mapv #(q/map-range % x1 x2 20 (- (q/width) 20))))]
|
(mapv #(q/map-range % x1 x2 20 (- (q/width) 20))))]
|
||||||
(q/point xx yy)))
|
(q/point xx yy)))
|
||||||
|
|
||||||
(defn draw-state
|
(defn draw-state
|
||||||
[state]
|
[state]
|
||||||
; (q/background 0 0 0)
|
|
||||||
(let [color (:color state)
|
(let [color (:color state)
|
||||||
step (:step state)]
|
step (:step state)]
|
||||||
; Set color.
|
; Set color.
|
||||||
(q/fill color 255 255)
|
(q/fill 255 255 255)
|
||||||
(q/stroke color 255 255)
|
(q/stroke color 255 155)
|
||||||
(q/stroke-weight 0.2)
|
(q/stroke-weight 0.2)
|
||||||
|
|
||||||
(if @keep-going
|
(if @keep-going
|
||||||
(do
|
(do
|
||||||
(doseq [x (range x1 x2 step)
|
(doseq [_ (range 12)]
|
||||||
y (range y1 y2 step)]
|
(doseq [x (range x1 x2 step)]
|
||||||
(draw-variation [x y] state))
|
(draw-variation [x @y] state))
|
||||||
(reset! keep-going false)))
|
(swap! y + step)
|
||||||
(q/ellipse 50 50 15 15)))
|
(if (> @y y2)
|
||||||
|
(reset! keep-going false)))))))
|
||||||
|
; (q/ellipse 50 50 15 15)))
|
||||||
|
|
||||||
(q/defsketch folds
|
(q/defsketch folds
|
||||||
:title "Folding"
|
:title "Folding"
|
||||||
:size [500 500]
|
:size [520 520]
|
||||||
; setup function called only once, during sketch initialization.
|
; setup function called only once, during sketch initialization.
|
||||||
:setup setup
|
:setup setup
|
||||||
; update-state is called on each iteration before draw-state.
|
; update-state is called on each iteration before draw-state.
|
||||||
|
|
Loading…
Reference in a new issue