add apostolos' present

This commit is contained in:
arne 2024-05-05 21:00:22 +02:00
commit 900ebf4c95

View file

@ -0,0 +1,93 @@
(ns aphorisms.thirty-six
(:require [quil.core :as q]
[quil.applet :as qa]
[quil.middleware :as qm]
[thi.ng.geom.rect :as r]
[thi.ng.geom.core :as g]
[thi.ng.geom.line :as l]
[thi.ng.math.core :as m]
[thi.ng.geom.vector :as v]
[heyarne.line-us.connection :as line-us]
[heyarne.line-us.gcode :as gcode]
[heyarne.line-us.helpers :as lh]))
;; apostolos' birthday present
(def bounds (g/scale (r/rect [218 342]) 2))
(def tau (* Math/PI 2))
(def line-spacing 10)
(def off-y 10)
(def padding 20)
(def lines
(->>
(for [y (range (+ (r/bottom bounds) padding)
(inc (- (r/top bounds) padding)) line-spacing)
:let [pos (/ (+ 1 (Math/sin (/ (g/height bounds) tau))) 2)
x-off (+ (r/left bounds) (* pos (g/width bounds)))]]
(l/linestrip2 [(+ (r/left bounds) padding) y] [x-off (+ y (* (Math/sin (* tau (/ (- y (+ (r/bottom bounds) padding)) (- (g/height bounds) padding)))) off-y))] [(- (r/right bounds) padding) y]))
(into [])))
(defn pad [rect p]
(let [p (v/vec2 p)]
(-> (update rect :p #(g/translate % p))
(update :size #(g/translate % (m/* p -2))))))
;; single circle
#_(def paths [[{:shape (c/circle (g/centroid bounds) 200)}]])
;; generated scene
(comment
;; plot currently visible scene
(with-open [line-us (line-us/connect "line-us.fritz.box" 1337)]
(line-us/send-command! line-us "G94 S2")
(doseq [#_#_coords (into [] cat (gcode/scene->gcode-seq [bounds])) ;; for calibration
coords (->> (gcode/scene->gcode-seq [lines])
(into [] cat)
#_(lh/rescale bounds))
#_#_coords (->>
(into [] (comp cat
(map :shape)
(map #(update % :p v/vec2))) ;; this is required because of a bug in the reader
paths)
(gcode/scene->gcode-seq)
(into [] cat)
#_(lh/rescale (r/rect [700 -1000] [1800 1000])))]
(line-us/send-movement! line-us coords)))
)
(defn setup []
(q/ellipse-mode :center)
(q/rect-mode :corners)
(q/color-mode :hsb 255)
{})
(defn draw-state [_]
(q/with-translation (m/* (:p bounds) -1))
(q/background 255)
(q/no-fill)
(doseq [l lines
[[x1 y1] [x2 y2]] (partition 2 1 (g/vertices l))]
(q/line x1 y1 x2 y2))
#_(doseq [path paths
{{[x y] :p r :r} :shape} path]
(q/ellipse x y (* 2 r) (* 2 r)))
#_(qd/draw-scene! scene))
#_:clj-kondo/ignore
(q/defsketch thirty-six
:title "Thirty-Six"
:size (:size bounds)
:settings #(q/pixel-density (q/display-density))
:features [:keep-on-top]
:setup setup
:update identity
:draw draw-state
:middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode])