-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial setup for degree-of-connectivity sketch
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(ns shimmers.sketches.degree-of-connectivity | ||
(:require | ||
[shimmers.algorithm.random-points :as rp] | ||
[shimmers.common.sequence :as cs] | ||
[shimmers.common.svg :as csvg :include-macros true] | ||
[shimmers.common.ui.controls :as ctrl] | ||
[shimmers.common.ui.svg :as usvg] | ||
[shimmers.math.deterministic-random :as dr] | ||
[shimmers.sketch :as sketch :include-macros true] | ||
[thi.ng.geom.circle :as gc] | ||
[thi.ng.geom.core :as g] | ||
[thi.ng.geom.line :as gl] | ||
[thi.ng.geom.rect :as rect] | ||
[thi.ng.geom.vector :as gv] | ||
[thi.ng.math.core :as tm])) | ||
|
||
;; basic concept: random graph but with weights on each edge based on logic like | ||
;; how many times it reduces planarity of the graph, so some are heavily shaded | ||
;; and others are just faint edges. | ||
|
||
(def width 800) | ||
(def height 600) | ||
(defn rv [x y] | ||
(gv/vec2 (* width x) (* height y))) | ||
|
||
(defn graph [bounds] | ||
(let [points (rp/poisson-disc-sampling (g/scale-size bounds 0.95) 50) | ||
max-dist (g/dist (g/unmap-point bounds (gv/vec2 0 0)) | ||
(g/unmap-point bounds (gv/vec2 1.0 1.0)))] | ||
{:points points | ||
:edges (for [[p q] (cs/all-pairs points) | ||
:let [dist (g/dist p q) | ||
pd (/ dist max-dist)] | ||
:when (and (< pd 0.175) | ||
(< (dr/random) 0.5))] | ||
[p q])})) | ||
|
||
(defn connection [p q] | ||
(let [p' (rp/confusion-disk p 4.0) | ||
q' (rp/confusion-disk q 4.0)] | ||
(gl/line2 (tm/mix p' q' (dr/random 0.15)) | ||
(tm/mix p' q' (- 1.0 (dr/random 0.15)))))) | ||
|
||
(defn shapes [bounds] | ||
(let [g (graph bounds)] | ||
(concat (for [p (:points g)] | ||
(gc/circle p 1.5)) | ||
(for [[p q] (:edges g)] | ||
(csvg/group {} | ||
(into [] (repeatedly (dr/random-int 2 15) | ||
#(connection p q)))))))) | ||
|
||
(defn scene [{:keys [scene-id]}] | ||
(csvg/svg-timed {:id scene-id | ||
:width width | ||
:height height | ||
:stroke "black" | ||
:fill "white" | ||
:stroke-width 0.5} | ||
(shapes (rect/rect 0 0 width height)))) | ||
|
||
(sketch/definition degree-of-connectivity | ||
{:created-at "2024-12-19" | ||
:tags #{} | ||
:type :svg} | ||
(ctrl/mount (usvg/page sketch-args scene))) |