
/g,">").replace(/"/g,""").replace(/'/g,"'")}let s={},c=[];function d(e,n,t){s={...s,dynamic:e,core:n,leinProject:t}}function p(){c=["wh","with-style"]}window.onload=()=>{let{dynamic:n,core:t,leinProject:r}=s;if(n&&(document.getElementById("code-dynamic").innerHTML=l(n)),t&&(document.getElementById("code-core").innerHTML=l(t)),r&&(document.getElementById("code-lein-project").innerHTML=l(r)),c){let e={wh:';; Copyright (c) 2016 Tyler Hobbs\n;; MIT License\n;; https://github.com/thobbs/genartlib/\n(defn h\n "Returns a given percentage of the height Quil-specific."\n ([] (h 1.0))\n ([percentage] (* (height) percentage)))\n\n;; Copyright (c) 2016 Tyler Hobbs\n;; MIT License\n;; https://github.com/thobbs/genartlib/\n(defn w\n "Returns a given percentage of the width. Quil-specific."\n ([] (w 1.0))\n ([percentage] (* (width) percentage)))\n',"with-style":"(defmacro with-style [& body]\n `(do\n (q/push-style)\n (try\n ~@body\n (finally (q/pop-style)))))\n"},n=c.map(n=>e[n]).join("\n");document.getElementById("code-helpers").innerHTML=l(n)}e(a).addPlugin((0,o.number)()),e(a).highlightAll()}}),o("3PmhV",function(e,t){n(e.exports,"number",()=>r);let r=e=>({"after:highlightElement":({el:e,result:n,text:t})=>{let r=n.value.split("\n");r.pop();let a=r.length.toString().length,i=r.map((e,n)=>{let t=(n+1).toString().padStart(a);return`${e}`}).join("\n");e.innerHTML=i}})}),i("d3dEA"),i("7Y8VX");var l=i("dZ8Um");(0,l.make)("(ns sketch.dynamic\n (:require [easings.core :as ease]\n [clojure.set :as cset]\n [sketch.kdtree :as kd]\n [clojure.core.matrix :as mat]\n [artlib.quil.global :refer :all]\n [artlib.color.dictionary :as color]\n [genartlib.util :refer [w h]]\n [quil.core :as q]))\n\n(def palette (color/get-combination-hsb (color/init) :315))\n\n(def close-range 0.01)\n(def visible-range 0.13)\n(def friction -0.005)\n(def avoid-factor 0.04)\n(def align-factor 0.006)\n(def center-factor 0.010)\n(def edge 0.1)\n(def turn-factor 0.0005)\n(def max-speed 0.02)\n(def min-speed 0.005)\n(def speed-factor 0.002)\n(def steps 2)\n\n(defrecord Boid [pos vel id])\n(defn spawn-flock []\n (for [n (range 30)]\n (let [pos [(+ 0.5 (gauss 0 0.1)) (+ 0.5 (gauss 0 0.1))]\n vel [(gauss 0 0.01) (gauss 0 0.01)]]\n (Boid. pos vel n))))\n\n(defn update-physics [tree boid]\n (let [{pos :pos vel :vel} boid\n friction (mat/mul vel friction)\n\n [x y] pos\n interval close-range\n close-interval [[(- x interval) (+ x interval)] [(- y interval) (+ y interval)]]\n result (kd/interval-search tree close-interval)\n too-close (->> result\n (map #(:boid (meta %)))\n (filter #(not= boid %))\n set)\n sep-force (->> too-close\n (map #(mat/sub (:pos boid) (:pos %)))\n (apply mat/add)\n (mat/mul [avoid-factor avoid-factor]))\n\n interval visible-range\n close-interval [[(- x interval) (+ x interval)] [(- y interval) (+ y interval)]]\n result (kd/interval-search tree close-interval)\n visible (->> result\n (map #(:boid (meta %)))\n (filter #(not= boid %))\n (filter #(not (contains? too-close %))))\n num-visible (count visible)\n sum-vel (->> visible (map :vel) (apply mat/add))\n sum-pos (->> visible (map :pos) (apply mat/add))\n\n align-force (if (zero? num-visible) \n [0 0]\n (mat/mul (mat/sub \n (mat/div sum-vel num-visible) \n (:vel boid)) \n align-factor))\n\n center-force (if (zero? num-visible) \n [0 0]\n (mat/mul (mat/sub \n (mat/div sum-pos num-visible)\n (:pos boid)) \n center-factor))\n\n turn-force (cond\n (< x edge) [turn-factor 0]\n (> x (- 1 edge)) [(- turn-factor) 0]\n (< y edge) [0 turn-factor]\n (> y (- 1 edge)) [0 (- turn-factor)]\n :else [0 0])\n\n speed (mat/magnitude (:vel boid))\n maintain-speed-force (cond\n (> speed max-speed) \n (mat/mul (mat/normalise (:vel boid)) (- speed-factor))\n\n (< 1e-5 speed min-speed)\n (mat/mul (mat/normalise (:vel boid)) speed-factor)\n \n :else [0 0])\n\n dt (/ 1 steps)\n acc (mat/add \n friction \n sep-force \n align-force \n center-force \n turn-force\n maintain-speed-force)\n new-vel (mat/add vel (mat/mul acc dt))\n new-pos (mat/add pos (mat/mul new-vel dt))]\n\n (-> boid\n (assoc :pos new-pos :vel new-vel))))\n\n(def prev (atom []))\n(defn update-flock [old-flock] \n (let [tree (->> old-flock\n (map #(with-meta (:pos %) {:boid %}))\n kd/build-tree) \n new-flock (map #(update-physics tree %) old-flock)]\n (swap! prev #(if (< (count %) 50)\n (concat % [new-flock])\n (rest (concat % [new-flock]))))\n new-flock))\n\n(def flock (atom nil))\n(defn draw [state]\n (when (nil? @flock)\n (reset! prev [])\n (reset! flock (nth (iterate update-flock (spawn-flock)) (* 500 steps))))\n\n (swap! flock update-flock)\n (let [frame (:frame state)\n f (/ frame 300)]\n (q/background 0 0 10)\n (doseq [[idx current-flock] (map-indexed vector @prev)]\n (let [t (/ idx (max 1 (count @prev)))\n t (ease/ease-in-sine t)\n r (* 0.015 t)]\n (with-style \n (doseq [{[x y] :pos n :id} current-flock]\n (let [[hue sat bri] (nth (cycle palette) n)]\n (q/fill hue sat bri 0.8)\n (q/ellipse (w x) (h y) (w r) (h r)))))))))\n",'(ns sketch.core\n (:require [artlib.quil.middleware :refer [animation-mode]]\n [clojure.core.matrix :refer [set-current-implementation]]\n [quil.middleware :as qm]\n [sketch.dynamic :as dynamic]\n [quil.core :as q]))\n\n(set-current-implementation :vectorz)\n(println)\n\n(q/defsketch example\n :title "genuary-2024-19"\n :setup (fn [] {})\n :draw dynamic/draw\n :update identity\n :size [1080 1080]\n :animation {:render? true :dirname "1"}\n :middleware [qm/fun-mode animation-mode])\n\n','(defproject genuary-2024-19 "0.1.0-SNAPSHOT"\n :description "FIXME: write description"\n :url "https://example.com/FIXME"\n :license {:name "Apache License, Version 2.0"\n :url "https://www.apache.org/licenses/LICENSE-2.0.html"}\n :dependencies [[org.clojure/clojure "1.11.1"]\n [com.dedovic/artlib-core "0.0.10"]\n [com.dedovic/easings-clj "0.1.0"]\n [genartlib/genartlib "1.0.0"]] ; utility functions\n :jvm-opts ["-Xms4000m" "-Xmx4000M" ; 4GB heap size\n "-server"\n "-Dsun.java2d.uiScale=1.0"] ; adjust scaling for high DPI displays\n :source-paths ["src/clj"]\n :java-source-paths ["src/java"]\n :resource-paths ["resources"])\n'),(0,l.withDefaultHelpers)();
dynamic.clj
core.clj
helpers
project.clj