Compare commits
4 commits
1dbde7b1c3
...
5937c7d14f
| Author | SHA1 | Date | |
|---|---|---|---|
| 5937c7d14f | |||
| 0075c83b5e | |||
| fbbc60a39c | |||
| 3d091f3275 |
7 changed files with 203 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,5 +1,8 @@
|
||||||
/.direnv/
|
/.direnv/
|
||||||
/.cpcache/
|
/.cpcache/
|
||||||
|
/exports
|
||||||
|
/resources
|
||||||
|
.rebel_readline_history
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/clojure
|
# Created by https://www.gitignore.io/api/clojure
|
||||||
|
|
||||||
|
|
|
||||||
23
deps.edn
23
deps.edn
|
|
@ -1,7 +1,24 @@
|
||||||
{:deps {#_#_ org.clojure/clojure {:mvn/version "1.11.1"}
|
{#_#_ :mvn/repos {"jogl" {:url "https://jogamp.org/deployment/maven/"}}
|
||||||
quil/quil {:mvn/version "4.3.1563"}
|
:deps {#_#_ org.clojure/clojure {:mvn/version "1.11.1"}
|
||||||
|
quil/quil {:mvn/version "4.3.1563"
|
||||||
|
#_#_ :exclusions [org.jogamp.jogl/jogl-all
|
||||||
|
org.jogamp.gluegen/gluegen-rt]}
|
||||||
thi.ng/geom {:mvn/version "1.0.0-RC3"
|
thi.ng/geom {:mvn/version "1.0.0-RC3"
|
||||||
:exclusions [org.jogamp.jogl/jogl-all
|
:exclusions [org.jogamp.jogl/jogl-all
|
||||||
org.jogamp.gluegen/gluegen-rt]}
|
org.jogamp.gluegen/gluegen-rt]}
|
||||||
com.cnuernber/charred {:mvn/version "1.034"}
|
com.cnuernber/charred {:mvn/version "1.034"}
|
||||||
overtone/osc-clj {:mvn/version "0.9.0"}}}
|
overtone/osc-clj {:mvn/version "0.9.0"}
|
||||||
|
|
||||||
|
;; ;; native display code
|
||||||
|
;; org.jogamp.gluegen/gluegen-rt {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.gluegen/gluegen-rt$natives-macosx-universal {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.gluegen/gluegen-rt$natives-linux-amd64 {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.gluegen/gluegen-rt$natives-linux-aarch64 {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.gluegen/gluegen-rt$natives-windows-amd64 {:mvn/version "2.5.0"}
|
||||||
|
|
||||||
|
;; org.jogamp.jogl/jogl-all {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.jogl/jogl-all$natives-macosx-universal {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.jogl/jogl-all$natives-linux-amd64 {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.jogl/jogl-all$natives-linux-aarch64 {:mvn/version "2.5.0"}
|
||||||
|
;; org.jogamp.jogl/jogl-all$natives-windows-amd64 {:mvn/version "2.5.0"}
|
||||||
|
}}
|
||||||
|
|
|
||||||
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1741513245,
|
"lastModified": 1771432645,
|
||||||
"narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=",
|
"narHash": "sha256-ZqRiU5/c+1+QoeaMJJgpqjwimCSNnIl0AUW4z7Md6Ps=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1",
|
"rev": "02263f46911178e286242786fd6ea1d229583fbb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,14 @@
|
||||||
devShells.${system}.default = pkgs.mkShell rec {
|
devShells.${system}.default = pkgs.mkShell rec {
|
||||||
name = "quil-env";
|
name = "quil-env";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
pkgs.xorg_sys_opengl
|
|
||||||
pkgs.xorg.libXxf86vm
|
|
||||||
pkgs.xwayland
|
|
||||||
pkgs.clojure
|
pkgs.clojure
|
||||||
|
|
||||||
|
pkgs.libGL
|
||||||
|
pkgs.libxxf86vm
|
||||||
# pkgs.jogl
|
# pkgs.jogl
|
||||||
];
|
];
|
||||||
LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
|
LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
|
||||||
|
JAVA_OPTS = "-Dawt.useSystemAAFontSettings=lcd";
|
||||||
|
|
||||||
# wayland compat
|
# wayland compat
|
||||||
# see https://discourse.ubuntu.com/t/environment-variables-for-wayland-hackers/12750
|
# see https://discourse.ubuntu.com/t/environment-variables-for-wayland-hackers/12750
|
||||||
|
|
|
||||||
73
src/aphorisms/fourty.clj
Normal file
73
src/aphorisms/fourty.clj
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
(ns aphorisms.fourty
|
||||||
|
(:require [thi.ng.geom.core :as g]
|
||||||
|
[thi.ng.geom.vector :as v]
|
||||||
|
[quil.core :as q]
|
||||||
|
[quil.middleware :as qm]
|
||||||
|
[thi.ng.geom.rect :as r]
|
||||||
|
[aphorisms.utils.middleware :refer [screenshottable]]
|
||||||
|
))
|
||||||
|
|
||||||
|
;; Getting a feeling for the `thi.ng` API again; mostly playing around with how
|
||||||
|
;; to partition geometries into a grid and how to position things relative to
|
||||||
|
;; each other.
|
||||||
|
|
||||||
|
(def height 500 #_(int (* width (Math/sqrt 2))))
|
||||||
|
(def width #_500 (int (* height (Math/sqrt 2))))
|
||||||
|
(def padding (* height 0.1))
|
||||||
|
(def canvas (r/rect width height))
|
||||||
|
|
||||||
|
(defn center-in
|
||||||
|
"Centers `r2` in or around `r1`."
|
||||||
|
[r1 r2]
|
||||||
|
(g/translate (assoc r2 :p (:p r1))
|
||||||
|
(v/vec2 (* 0.5 (- (g/width r1) (g/width r2)))
|
||||||
|
(* 0.5 (- (g/height r1) (g/height r2))))))
|
||||||
|
|
||||||
|
(def bounds (center-in canvas (r/rect (- width (* 2 padding)) (- height (* 2 padding)))))
|
||||||
|
|
||||||
|
(defn as-grid [rect cell-size]
|
||||||
|
(let [n-x (int (/ (g/width rect) cell-size))
|
||||||
|
n-y (int (/ (g/height rect) cell-size))
|
||||||
|
t (v/vec2 (* (mod (g/width rect) n-x) 0.5)
|
||||||
|
(* (mod (g/height rect) n-x) 0.5))]
|
||||||
|
(for [x (range n-x)
|
||||||
|
y (range n-y)]
|
||||||
|
(-> (r/rect (* x cell-size) (* y cell-size) cell-size)
|
||||||
|
(g/translate (:p rect))
|
||||||
|
(g/translate t )))))
|
||||||
|
|
||||||
|
(def grid (as-grid bounds 20))
|
||||||
|
|
||||||
|
;; below is the rendering logic
|
||||||
|
|
||||||
|
(defn setup []
|
||||||
|
(q/frame-rate 30)
|
||||||
|
(q/color-mode :hsb 360 100 100)
|
||||||
|
(q/rect-mode :center)
|
||||||
|
(q/ellipse-mode :center)
|
||||||
|
(q/background 350)
|
||||||
|
{})
|
||||||
|
|
||||||
|
(defn update-state [state]
|
||||||
|
state)
|
||||||
|
|
||||||
|
(defn draw-state [state]
|
||||||
|
(q/translate -0.5)
|
||||||
|
(q/background 180 0 98)
|
||||||
|
(q/stroke-weight 0.5)
|
||||||
|
(q/no-fill)
|
||||||
|
(q/stroke 320 100 70)
|
||||||
|
(doseq [cell grid
|
||||||
|
:let [[x y] (g/centroid cell)]]
|
||||||
|
(q/ellipse x y 10 10)))
|
||||||
|
|
||||||
|
#_:clj-kondo/ignore
|
||||||
|
(q/defsketch fourty
|
||||||
|
:title "Fourty"
|
||||||
|
:size [width height]
|
||||||
|
: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 (screenshottable)])
|
||||||
99
src/aphorisms/fourty_one.clj
Normal file
99
src/aphorisms/fourty_one.clj
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
(ns aphorisms.fourty-one
|
||||||
|
(:require [thi.ng.geom.core :as g]
|
||||||
|
[thi.ng.geom.vector :as v]
|
||||||
|
[quil.core :as q]
|
||||||
|
[quil.middleware :as qm]
|
||||||
|
[thi.ng.geom.rect :as r]
|
||||||
|
[aphorisms.utils.middleware :refer [screenshottable]]
|
||||||
|
|
||||||
|
[thi.ng.geom.line :as l]
|
||||||
|
[thi.ng.math.core :as m]
|
||||||
|
[thi.ng.geom.utils.intersect :as isec]))
|
||||||
|
|
||||||
|
;; More practice to get a feeling for the `thi.ng` API again
|
||||||
|
;; Resizing cells in the grid, generating random lines and playing with intersections
|
||||||
|
|
||||||
|
(def height 500 #_(int (* width (Math/sqrt 2))))
|
||||||
|
(def width #_500 (int (* height (Math/sqrt 2))))
|
||||||
|
(def padding (* height 0.1))
|
||||||
|
(def canvas (r/rect width height))
|
||||||
|
|
||||||
|
(defn center-in
|
||||||
|
"Centers `r2` in or around `r1`."
|
||||||
|
[r1 r2]
|
||||||
|
(g/translate (assoc r2 :p (:p r1))
|
||||||
|
(v/vec2 (* 0.5 (- (g/width r1) (g/width r2)))
|
||||||
|
(* 0.5 (- (g/height r1) (g/height r2))))))
|
||||||
|
|
||||||
|
(def bounds (center-in canvas (r/rect (- width (* 2 padding)) (- height (* 2 padding)))))
|
||||||
|
|
||||||
|
(defn as-grid [rect cell-size]
|
||||||
|
(let [n-x (int (/ (g/width rect) cell-size))
|
||||||
|
n-y (int (/ (g/height rect) cell-size))
|
||||||
|
t (v/vec2 (* (mod (g/width rect) (* cell-size n-x)) 0.5)
|
||||||
|
(* (mod (g/height rect) (* cell-size n-x)) 0.5))]
|
||||||
|
(for [x (range n-x)
|
||||||
|
y (range n-y)]
|
||||||
|
(-> (r/rect (* x cell-size) (* y cell-size) cell-size)
|
||||||
|
(g/translate (:p rect))
|
||||||
|
(g/translate t )))))
|
||||||
|
|
||||||
|
(def grid (map #(g/scale-size % 0.92) (as-grid bounds 50)))
|
||||||
|
|
||||||
|
(defn line-inside [rect]
|
||||||
|
(l/line2 (g/random-point-inside rect) (g/random-point-inside rect)))
|
||||||
|
|
||||||
|
;; below is the rendering logic
|
||||||
|
|
||||||
|
(defn setup []
|
||||||
|
(q/frame-rate 30)
|
||||||
|
(q/color-mode :hsb 360 100 100)
|
||||||
|
(q/rect-mode :center)
|
||||||
|
(q/ellipse-mode :center)
|
||||||
|
(q/background 350)
|
||||||
|
{:lines (repeatedly 5 #(line-inside bounds))})
|
||||||
|
|
||||||
|
(defn update-state [state]
|
||||||
|
state)
|
||||||
|
|
||||||
|
(defn mouse-pressed [state _]
|
||||||
|
(assoc state :lines (repeatedly 20 #(line-inside bounds))))
|
||||||
|
|
||||||
|
(let [l (l/line2 50 50 200 210)]
|
||||||
|
(g/intersect-line l (first (g/edges (first grid)))))
|
||||||
|
|
||||||
|
(defn draw-state [state]
|
||||||
|
(q/translate -0.5 -0.5)
|
||||||
|
(q/background 180 0 98)
|
||||||
|
(q/stroke-weight 0.5)
|
||||||
|
(q/no-fill)
|
||||||
|
(q/stroke 320 100 70)
|
||||||
|
(doseq [line (:lines state)
|
||||||
|
:let [[a b] (g/vertices line)]]
|
||||||
|
(q/line a b))
|
||||||
|
(doseq [cell grid
|
||||||
|
[a b] (g/edges cell)]
|
||||||
|
(q/line a b))
|
||||||
|
(q/no-stroke)
|
||||||
|
(q/fill 320 100 70)
|
||||||
|
(doseq [cell grid
|
||||||
|
line (:lines state)
|
||||||
|
isecs (->>
|
||||||
|
(map #(g/intersect-line line %) (g/edges cell))
|
||||||
|
(keep #(when (= (:type %) :intersect) (:p %))))
|
||||||
|
:let [[i1 i2] isecs]]
|
||||||
|
(q/ellipse i1 i2 5 5)))
|
||||||
|
|
||||||
|
#_:clj-kondo/ignore
|
||||||
|
(q/defsketch fourty-one
|
||||||
|
:title "Fourty One"
|
||||||
|
:size [width height]
|
||||||
|
:settings (fn []
|
||||||
|
(q/smooth 2)
|
||||||
|
(q/pixel-density (q/display-density)))
|
||||||
|
:setup setup
|
||||||
|
:update #'update-state
|
||||||
|
:mouse-pressed #'mouse-pressed
|
||||||
|
:draw #'draw-state
|
||||||
|
:features [:keep-on-top :no-bind-output]
|
||||||
|
:middleware [qm/pause-on-error qm/fun-mode (screenshottable)])
|
||||||
|
|
@ -31,4 +31,4 @@
|
||||||
(q/save path)))
|
(q/save path)))
|
||||||
(when (fn? key-pressed)
|
(when (fn? key-pressed)
|
||||||
(key-pressed state ev))
|
(key-pressed state ev))
|
||||||
{}))))))
|
state))))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue