61 lines
1.7 KiB
Clojure
61 lines
1.7 KiB
Clojure
(ns heyarne.all-my-friends.core
|
|
(:require [quil.core :as q]
|
|
[quil.middlewares.pause-on-error :refer [pause-on-error]]
|
|
[camel-snake-kebab.core :refer [->kebab-case]]
|
|
[cheshire.core :as json]
|
|
[thi.ng.geom.vector :as v]
|
|
[thi.ng.geom.core :as g]
|
|
[thi.ng.math.core :as m]
|
|
[clojure.java.io :as io]
|
|
[clojure.string :as str]))
|
|
|
|
;; TODO All PNGs are missing an extension
|
|
(def uploads
|
|
#?(:clj (->>
|
|
(map bean (file-seq (io/file "../uploads")))
|
|
(filter :file)
|
|
(remove :hidden)
|
|
(sort-by :name)
|
|
(partition-by #(first (str/split (:name %) #"\."))))
|
|
:cljs [])) ;; TODO
|
|
|
|
(def key-fn (comp keyword ->kebab-case))
|
|
|
|
(defn parse-most-recent [uploads]
|
|
(when-let [most-recent (last uploads)]
|
|
(let [[_image computational-gaze] most-recent]
|
|
#?(:clj
|
|
(with-open [rdr (io/reader (:path computational-gaze))]
|
|
(json/parse-stream rdr key-fn))
|
|
:cljs nil)))) ;; TODO
|
|
|
|
(def most-recent (parse-most-recent uploads))
|
|
|
|
;; "most-recent" now contains a seq of all faces detected in the most recently
|
|
;; uploaded picture
|
|
|
|
(defn setup []
|
|
(q/frame-rate 60)
|
|
(q/color-mode :hsb))
|
|
|
|
(defn draw []
|
|
(q/clear)
|
|
(q/background 40 80 255)
|
|
(q/stroke 240 100 255)
|
|
(q/stroke-weight 1)
|
|
(q/no-fill)
|
|
|
|
(doseq [face most-recent
|
|
:let [mesh (:mesh face)]]
|
|
(doseq [[[x1 y1 z1] pt2] (partition 2 mesh)]
|
|
(q/line x1 y1 (+ (q/random -2 2) x1) (+ (q/random -2 2) y1))
|
|
#_(apply q/line pt1 pt2))))
|
|
|
|
#_:clj-kondo/ignore
|
|
(q/defsketch all-my-friends
|
|
:title "These are all my friends"
|
|
:settings #(q/smooth 2)
|
|
:middleware [pause-on-error]
|
|
:setup setup
|
|
:draw draw
|
|
:size [500 500])
|