diff --git a/src/aphorisms/twenty-one.clj b/src/aphorisms/twenty-one.clj new file mode 100644 index 0000000..4e878eb --- /dev/null +++ b/src/aphorisms/twenty-one.clj @@ -0,0 +1,86 @@ +(ns aphorisms.twenty-one + (:require [quil.core :as q] + [quil.middleware :as qm] + [thi.ng.geom.rect :as r] + [clojure.string :as str])) + +;; https://10print.org/ + +(def bounds (r/rect 540 960)) + +(defn setup [] + (q/frame-rate 30) + (q/rect-mode :center) + (q/ellipse-mode :center) + (q/color-mode :hsb 100 100 100) + {:x-off 0.022 + :y-off 0.033}) + +(defn update-state [state] + state) + +(def tile-size 30) + +(defn draw-tile [[x y] tile-type] + (let [start (case tile-type + :a 0 + :b q/HALF-PI)] + (q/arc x y tile-size tile-size start (+ start q/PI)))) + +(defn pick-at [xs rand-val] + (nth xs (Math/round (* rand-val (dec (count xs)))))) + +(defn draw-state [state] + (let [margin (* 2 tile-size) + grey-tone (/ 100 16)] + (q/no-fill) + (q/background (* 2 grey-tone)) + (q/stroke 0 0 (* 14 grey-tone)) + (q/stroke-weight 3) + (q/stroke-cap :round) + (doseq [y (range margin (- (-> bounds :size :y) margin -1) tile-size) + x (range margin (- (-> bounds :size :x) margin -1) tile-size) + :let [n (q/noise (* (:x-off state) x #_(q/millis)) + (* (:y-off state) y #_(q/millis)))]] + (draw-tile [x y] (pick-at [:a :b] n))))) + +;; sketch export logic + +(defn current-time [] + (-> + (.format java.time.format.DateTimeFormatter/ISO_LOCAL_DATE_TIME (java.time.LocalDateTime/now)) + (str/replace #"\.\d+$" "") + (str/replace #":" "-"))) + +(defn export [{:keys [x-prog y-prog]}] + (let [filename (format "%s-x%s-y%s-%s.png" *ns* x-prog y-prog (current-time))] + (q/save filename) + (println "Saved current sketch to " filename))) + +(defn key-pressed [state {k :raw-key}] + (cond + (#{\e \s} k) + (do + (export state) + state) + + (= k \r) + (let [x-off (* (rand-int 1000) 0.0001) + y-off (* (rand-int 1000) 0.0001)] + (println "New offsets: " x-off ", " y-off) + (-> (assoc state :x-off x-off) + (assoc :y-off y-off))) + + :else state)) + +#_:clj-kondo/ignore +(q/defsketch twenty-one + :title "Twenty-One" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + :update update-state + :draw draw-state + :key-pressed key-pressed + :middleware [qm/pause-on-error qm/fun-mode] + :features [:keep-on-top]) diff --git a/src/aphorisms/twenty_five.clj b/src/aphorisms/twenty_five.clj new file mode 100644 index 0000000..e72919e --- /dev/null +++ b/src/aphorisms/twenty_five.clj @@ -0,0 +1,52 @@ +(ns aphorisms.twenty-five + (:require [quil.core :as q] + [quil.middleware :as qm] + [thi.ng.geom.rect :as r] + [thi.ng.geom.core :as g])) + +(def bounds (r/rect 200 200)) + +(defn setup [] + (q/frame-rate 30) + (q/ellipse-mode :center) + (q/color-mode :hsb 100) + {}) + +(defn update-state [_] + _) + +(defn divisors [n] + (->> + (range 1 (inc (int (/ n 2)))) + (filter #(zero? (rem n %))))) + +(divisors 800) +;; => (1 2 4 5 8 10 16 20 25 32 40 50 80 100 160 200 400) +(divisors 230) +;; => (1 2 5 10 23 46 115) + +(def x-noise-scale 0.006) +(def y-noise-scale 0.005) + +(defn draw-state [_] + (q/background 100) + (q/stroke-weight 1) + (doseq [y (range 0 (inc (- (g/height bounds) 10)) 10) + x (range 0 (inc (- (g/width bounds) 10)) 10) + :let [noise-x (* x x-noise-scale) + noise-y (* y y-noise-scale)]] + (q/with-translation [(+ x 5) (+ y 5)] + (q/with-rotation [(* q/TWO-PI (q/noise noise-x noise-y))] + (q/stroke (q/map-range (* noise-x noise-y) -1 1 90 70) 60 80) + (q/line [-3 0] [3 0])))) + (q/save-frame "exports/twenty-five--business-card.png")) + +#_:clj-kondo/ignore +(q/defsketch twenty-five + :title "Twenty-Five" + :size (:size bounds) + :settings #(q/pixel-density (q/display-density)) + :setup setup + :update update-state + :draw draw-state + :middleware [qm/pause-on-error qm/fun-mode]) diff --git a/src/aphorisms/twenty_four.clj b/src/aphorisms/twenty_four.clj index c324ab4..eb1643f 100644 --- a/src/aphorisms/twenty_four.clj +++ b/src/aphorisms/twenty_four.clj @@ -5,10 +5,6 @@ [thi.ng.geom.core :as g] [thi.ng.math.core :as m])) -;; I'm in bed. It is 9th of October, the temperatures are mild, the sund is -;; shining and my girlfriend is reading me texts about the physical appearance -;; of angels. - (def bounds (r/rect 540 960)) (defn setup []