This is ground control to major tom
This commit is contained in:
parent
c62e13c3d1
commit
f2a2bffccf
4 changed files with 126 additions and 2 deletions
77
src/aphorisms/seven.clj
Normal file
77
src/aphorisms/seven.clj
Normal file
|
|
@ -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])
|
||||
48
src/aphorisms/six.clj
Normal file
48
src/aphorisms/six.clj
Normal file
|
|
@ -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])
|
||||
Loading…
Add table
Add a link
Reference in a new issue