From d88a17f54e1fef02523ed4ff892b623311888677 Mon Sep 17 00:00:00 2001 From: arne Date: Wed, 31 Aug 2022 20:13:55 +0200 Subject: [PATCH] Twenty-eight till thirty-one --- flake.lock | 6 +-- src/aphorisms/thirty.clj | 57 ++++++++++++++++++++++++++++ src/aphorisms/thirty_one.clj | 49 ++++++++++++++++++++++++ src/aphorisms/twenty_eight.clj | 41 ++++++++++++++++++++ src/aphorisms/twenty_nine.clj | 60 ++++++++++++++++++++++++++++++ src/aphorisms/utils/middleware.clj | 21 +++++++++++ 6 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 src/aphorisms/thirty.clj create mode 100644 src/aphorisms/thirty_one.clj create mode 100644 src/aphorisms/twenty_eight.clj create mode 100644 src/aphorisms/twenty_nine.clj create mode 100644 src/aphorisms/utils/middleware.clj diff --git a/flake.lock b/flake.lock index fdc39b3..78fd844 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1623662708, - "narHash": "sha256-70k/89Pr935xNSkUeiLUWavk6fGaFWM+HgClQPHU4YY=", + "lastModified": 1667514353, + "narHash": "sha256-zaYpmXs2gWh/KeFyNTcNKd0ibuWLvNV0S62fagVEnQs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "799cdbd8342c5ad3adbede25caf6d544c56f019b", + "rev": "45b546681874b344a53bdeb01bd41f13a5cfeba0", "type": "github" }, "original": { diff --git a/src/aphorisms/thirty.clj b/src/aphorisms/thirty.clj new file mode 100644 index 0000000..8129991 --- /dev/null +++ b/src/aphorisms/thirty.clj @@ -0,0 +1,57 @@ +(ns aphorisms.thirty + (:require [quil.core :as q] + [quil.middleware :as qm] + [aphorisms.utils.middleware :refer [screenshottable]] + [thi.ng.math.core :as m] + [thi.ng.math.noise :as n] + [thi.ng.geom.line :as l] + [thi.ng.geom.rect :as r] + [thi.ng.geom.core :as g] + [thi.ng.geom.polygon :as p] + [thi.ng.geom.vector :as v])) + +(def bounds (r/rect 500 500)) +(def canvas (g/scale bounds 0.92)) + +(defn setup [] + (q/frame-rate 30) + (q/ellipse-mode :center) + (q/rect-mode :corners) + (q/color-mode :hsb 255) + {}) + + +(defn noise-line [x y intensity] + (->> (map (fn [i] + (v/vec2 (+ x (* 10 (n/noise2 (* x 0.003) (* i 0.2)))) + (+ y (* i (n/noise1 (+ x 0.4)))))) + (range intensity)) + (l/linestrip2))) + +(g/subdivide bounds {:num 4}) + +(defn draw-state [_] + (q/background 232) + (q/no-fill) + (q/stroke 140) + (q/with-translation [(/ (- (g/width bounds) (g/width canvas)) 4) + (/ (- (g/height bounds) (g/height canvas)) 2)] + (doseq [sector (g/subdivide canvas {:rows 5 + :cols 6}) + :let [[x y] (g/centroid sector) + line (noise-line x y (* 0.1 (- (g/height bounds) y)))]] + (doseq [[from to] (->> (g/vertices line) + (partition 2 1))] + #_(q/scale 0 -1) + (q/line from to))))) + + +#_:clj-kondo/ignore +(q/defsketch thirty + :title "Thirty" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + ;; :update update-state + :draw draw-state + :middleware [qm/pause-on-error (screenshottable) qm/fun-mode]) diff --git a/src/aphorisms/thirty_one.clj b/src/aphorisms/thirty_one.clj new file mode 100644 index 0000000..55e1c61 --- /dev/null +++ b/src/aphorisms/thirty_one.clj @@ -0,0 +1,49 @@ +(ns aphorisms.thirty-one + (:require [quil.core :as q] + [quil.middleware :as qm] + [thi.ng.geom.rect :as r] + [thi.ng.geom.core :as g] + [thi.ng.geom.circle :as c] + [thi.ng.math.core :as m])) + +(def bounds (r/rect 600 600)) +(def canvas (g/scale bounds 0.92)) + +(defn setup [] + (q/frame-rate 30) + (q/ellipse-mode :center) + (q/rect-mode :corners) + (q/color-mode :hsb 255) + {}) + +(def circ + (c/circle 100)) + +(defn draw-state [_] + (let [t (* 0.0002 (q/millis))] + (q/background 232) + (q/fill 255) + (q/no-stroke) + (q/blend-mode :difference) + (q/with-translation [(/ (g/width bounds) 2) + (/ (g/height bounds) 2)] + (q/ellipse 0 0 (g/width circ) (g/height circ)) + + (doseq [i (range 12) + :let [offset (* 0.82 (g/height circ))]] + (q/ellipse (* offset (Math/cos (- i t))) (* offset (Math/sin (- i t))) (* 0.41 (g/width circ)) (* 0.41 (g/height circ)))) + + (doseq [i (mapv (fn [i] (/ i m/TWO_PI )) (range 1 41)) + :let [offset (* 1.23 (g/height circ)) + circumference (* m/TWO_PI offset)]] + (q/ellipse (* offset (Math/cos (+ t i))) (* offset (Math/sin (+ t i))) (/ circumference 80) (/ circumference 80)))))) + +#_:clj-kondo/ignore +(q/defsketch thirty-one + :title "Thirty-One" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + ;; :update update-state + :draw draw-state + :middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode]) diff --git a/src/aphorisms/twenty_eight.clj b/src/aphorisms/twenty_eight.clj new file mode 100644 index 0000000..a7ec978 --- /dev/null +++ b/src/aphorisms/twenty_eight.clj @@ -0,0 +1,41 @@ +(ns aphorisms.twenty-eight + (:require [quil.core :as q] + [quil.middleware :as qm] + [aphorisms.utils.middleware :refer [screenshottable]] + [thi.ng.geom.rect :as r] + [thi.ng.geom.core :as g])) + +(def bounds (r/rect 640 480)) + +(defn setup [] + (q/frame-rate 30) + (q/ellipse-mode :center) + (q/color-mode :hsb 255) + {}) + +(defn draw-state [_] + (q/background 255) + (q/stroke 40) + (q/fill 255) + + (q/with-translation [(* 0.5 (q/width)) + (* 0.5 (q/height))] + (doseq [i (range -5 5) + :let [r (q/map-range i -5 4 20 32) + x (* i (* (q/sin i) 0.2) 20) + y (q/map-range i -5 4 -20 40) + ]] + (q/ellipse x y r r)))) + +; define 2 images and a mask to apply to them + + +#_:clj-kondo/ignore +(q/defsketch twenty-eight + :title "Twenty-Eight" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + :update update-state + :draw draw-state + :middleware [(screenshottable) qm/pause-on-error qm/fun-mode]) diff --git a/src/aphorisms/twenty_nine.clj b/src/aphorisms/twenty_nine.clj new file mode 100644 index 0000000..52beffd --- /dev/null +++ b/src/aphorisms/twenty_nine.clj @@ -0,0 +1,60 @@ +(ns aphorisms.twenty-nine + (:require [quil.core :as q] + [quil.middleware :as qm] + [aphorisms.utils.middleware :refer [screenshottable]] + [thi.ng.math.core :as m] + [thi.ng.geom.line :as l] + [thi.ng.geom.rect :as r] + [thi.ng.geom.core :as g] + [thi.ng.geom.polygon :as p])) + +(def bounds (r/rect 640 480)) + +(defn setup [] + (q/frame-rate 30) + (q/ellipse-mode :center) + (q/rect-mode :corners) + (q/color-mode :hsb 255) + {}) + +(def line (l/line2 [0 (rand-int (g/height bounds))] + [(g/width bounds) (rand-int (g/height bounds))])) + +(defn spaced-line [l s] + (let [spacer (-> (g/translate line (m/- (nth (g/vertices line) 0))) + (m/normalize) + (g/rotate m/HALF_PI) + (g/scale-size s))] + (g/translate l (nth (g/vertices spacer) 1)))) + +(defn line2->poly2 [l] + (p/polygon2 (g/vertices l))) + +(line2->poly2 line) + +(defn line-pattern [bounds line dist] + ;; 1. move line to top of bounds so that it barely still touches it + ;; 2. repeat line, spacing it by dist, so that it fills the complete bounds + + ) + +(defn draw-state [_] + (q/background 255) + (q/no-fill) + (q/stroke-weight 3) + (q/stroke 120) + (q/with-translation [(* 0.5 (q/width)) + (* 0.5 (q/height))] + (q/rect -100 -100 100 100 3)) + (doseq [line (reductions spaced-line line (range 10 101 10))] + (apply q/line (g/vertices line)))) + +#_:clj-kondo/ignore +(q/defsketch twenty-nine + :title "Twenty-Nine" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + ;; :update update-state + :draw draw-state + :middleware [(screenshottable) qm/pause-on-error qm/fun-mode]) diff --git a/src/aphorisms/utils/middleware.clj b/src/aphorisms/utils/middleware.clj new file mode 100644 index 0000000..4faafaf --- /dev/null +++ b/src/aphorisms/utils/middleware.clj @@ -0,0 +1,21 @@ +(ns aphorisms.utils.middleware + (:require [quil.core :as q])) + +(defn- default-name-fn [timestamp] + (println "*ns*" *ns*) + (format "%s.png" timestamp)) + +(defn screenshottable + ([] (screenshottable {})) + ([{:keys [out-dir name-fn] + :or {out-dir "exports" + name-fn default-name-fn}}] + (fn screenshottable [opts] + (let [key-pressed (:key-pressed opts)] + (when (fn? key-pressed) + (println "There is already a function bound to key-pressed.")) + (assoc opts :key-pressed + (fn [e] + (println e) + (when (fn? key-pressed) + (key-pressed e))))))))