diff --git a/project.clj b/project.clj index 76c16c1..2973b53 100644 --- a/project.clj +++ b/project.clj @@ -6,5 +6,4 @@ :dependencies [[org.clojure/clojure "1.9.0"] [quil "2.8.0"] [thi.ng/geom "1.0.0-RC3" :exclusions [org.jogamp.jogl/jogl-all - org.jogamp.gluegen/gluegen-rt]]] - :main aphorisms.core) + org.jogamp.gluegen/gluegen-rt]]]) diff --git a/resources/ghost-of-cassiopeia.png b/resources/ghost-of-cassiopeia.png new file mode 100644 index 0000000..9db7b06 Binary files /dev/null and b/resources/ghost-of-cassiopeia.png differ diff --git a/src/aphorisms/seven.clj b/src/aphorisms/seven.clj new file mode 100644 index 0000000..0c2e252 --- /dev/null +++ b/src/aphorisms/seven.clj @@ -0,0 +1,77 @@ +(ns aphorisms.seven + (:require [thi.ng.geom.vector :as v] + [thi.ng.math.core :as m] + [quil.core :as q] + [quil.middleware :as qm])) + +(set! *warn-on-reflection* true) + +(defmacro + ^{:requires-bindings true + :processing-name nil + :category "Rendering" + :added "1.7"} + with-graphics + "All subsequent calls of any drawing function will draw on given + graphics. 'with-graphics' cannot be nested (you can draw simultaneously + only on 1 graphics)" + [graphics & body] + `(let [^processing.core.PGraphics gr# ~graphics] + (binding [quil.core/*graphics* gr#] + (.beginDraw gr#) + ~@body + (.endDraw gr#)))) + +(defn fit-to-screen [^processing.core.PImage img] + (if (> (.-width img) (.-height img)) + (.resize img (* (.-width img) (/ (q/height) (.-height img))) (q/height)) + (.resize img (q/width) (* (.-height img) (/ (q/width) (.-width img))))) + img) + +(defn setup [] + (let [mask (q/create-graphics (q/width) (q/height) :p3d) + img-canvas (q/create-graphics (q/width) (q/height) :p3d)] + (q/frame-rate 30) + (q/color-mode :hsb) + (q/image-mode :center) + (with-graphics mask + (q/background 0)) + (with-graphics img-canvas + (let [img (-> (q/load-image "ghost-of-cassiopeia.png") + fit-to-screen)] + (q/image-mode :center) + (q/image img (* 0.5 (q/width)) (* 0.5 (q/height))))) + {:img img-canvas + :mask mask + :theta 0})) + +(defn update-state [state] + state) + +(defn mouse-moved [state ev] + (assoc state :mouse ev)) + +(defn draw-state [state] + (when (:mouse state) + (with-graphics (:mask state) + (q/background 0) + (q/fill (int (* 255 (/ (get-in state [:mouse :x]) (q/width))))) + (q/ellipse-mode :center) + (q/ellipse (get-in state [:mouse :x]) (get-in state [:mouse :y]) 100 100))) + (q/fill 221 40 250) + (q/rect 0 0 (q/width) (q/height)) + (q/with-translation [(* 0.5 (q/width)) (* 0.5 (q/height))] + (q/mask-image (:img state) (:mask state)) + (q/image (:img state) 0 0))) + +(q/defsketch seven + :title "Ghost of Cassiopeia" + :size [500 500] + :settings #(q/pixel-density (q/display-density)) + :renderer :p3d + :setup setup + :update update-state + :draw draw-state + :mouse-moved mouse-moved + :features [:keep-on-top :no-bind-output] + :middleware [qm/pause-on-error qm/fun-mode]) diff --git a/src/aphorisms/six.clj b/src/aphorisms/six.clj new file mode 100644 index 0000000..b6fc13c --- /dev/null +++ b/src/aphorisms/six.clj @@ -0,0 +1,48 @@ +(ns aphorisms.six + (:require [quil.core :as q] + [quil.middleware :as qm])) + +(def n-pendulums 20) + +(defn setup [] + (let [start 100 + end 400] + (q/frame-rate 30) + (q/color-mode :hsb) + ;; each pendulum is just an x and a y coordinate + {:pendulums (mapv (fn [i] + {:pos [(/ (q/width) 2) + (+ start (* i (/ (- end start) n-pendulums)))] + :rad 0}) + (range n-pendulums))})) + +(defn update-state [state] + state + #_(update state :pendulums #(map + (fn [p] + (update p :rad (partial + (q/sin (/ (q/millis) 2000))))) + %))) + +(defn draw-state [state] + (q/background 240) + (q/no-fill) + (q/stroke 230) + (doseq [{[x y] :pos} (:pendulums state)] + (let [x (+ x (* 10 (q/sin (* 0.00002 y (q/millis))))) + y (+ y (* 2 (q/sin (* 0.00002 y (q/millis)))))] + (q/line 250 50 x y))) + (q/stroke 190) + (doseq [{[x y] :pos} (:pendulums state)] + (let [x (+ x (* (* y 0.003 10) (q/sin (* 0.00002 y (q/millis))))) + y (+ y (* 2 (q/sin (* 0.00002 y (q/millis)))))] + (q/ellipse x y 5 5)))) + +(q/defsketch six + :title "" + :size [500 500] + :settings #(q/pixel-density (q/display-density)) + :setup setup + :update update-state + :draw draw-state + :features [:keep-on-top :no-bind-output] + :middleware [qm/pause-on-error qm/fun-mode])