Skip to content

Commit ee95624

Browse files
authored
Merge pull request #13 from genmeblog/main
simplification of curve rendering
2 parents 08cb85f + 071447e commit ee95624

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

notebooks/logo.clj

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@
3333

3434
;; But they're much more interesting if we use
3535
;; [Clojure2D](https://github.com/Clojure2D/clojure2d) canvas to draw
36-
;; a line between every pair of points to show the complete curve:
36+
;; a path made from points to show the complete curve:
3737
(c2d/with-canvas [canvas (c2d/canvas 800 800 :highest)]
3838
(-> canvas
3939
(c2d/set-background 255 255 255)
4040
(c2d/set-color 66 66 66)
41-
(c2d/set-stroke 4))
42-
(doseq [[[x1 y1] [x2 y2]] (partition 2 1 hilbert-points)]
43-
(c2d/line canvas x1 y1 x2 y2))
41+
(c2d/set-stroke 4)
42+
(c2d/path hilbert-points))
4443
;; just the underlying BufferedImage, please
45-
(:buffer canvas))
44+
(c2d/to-image canvas))
4645

4746
;; The trick to getting the effect we want is to apply a conformal
4847
;; mapping to the original Hilbert Curve to convert it into an 👁 shape
49-
;; in celebration of Clerk's viewers. We can do this by projecting the
50-
;; original point coordinates of our curve onto the complex plane,
48+
;; in celebration of Clerk's viewers. We can do this by treating the
49+
;; original point coordinates as complex numbers,
5150
;; squaring them, then taking the real and imaginary portions of each
5251
;; of those complex numbers as the _x_ and _y_ coordinates of a new
5352
;; set of points. This is made especially easy because Clojure2D
@@ -65,22 +64,21 @@
6564
;; ellipses to fill in the center of the "eye"
6665
(c2d/ellipse 0 0 22 22)
6766
(c2d/ellipse 0 -10 20 20)
68-
(c2d/ellipse 0 10 20 20))
69-
(doseq [[[x1 y1] [x2 y2]] (->> hilbert-points
70-
(mapv (fn [p]
71-
;; center the curve
72-
(->> (v/sub p (v/vec2 400 400))
73-
;; convert to complex, square
74-
(apply complex/complex)
75-
(complex/sq)
76-
;; scale the squared values down
77-
(map (partial * 0.0015)))))
78-
(partition 2 1))]
79-
(c2d/line canvas x1 y1 x2 y2))
80-
(:buffer canvas))
67+
(c2d/ellipse 0 10 20 20)
68+
;; create a path from complex square of hilbert curve points
69+
(c2d/path (map (fn [p]
70+
;; center the curve
71+
(-> (v/sub p (v/vec2 400 400))
72+
;; square it (as complex numbers!)
73+
(complex/sq)
74+
;; scale the squared values down
75+
(v/mult 0.0015))) hilbert-points)))
76+
(c2d/to-image canvas))
8177

8278
;; What I find so special and enchanting about the $$w = z^{2}$$
8379
;; mapping that we're using here is that it maintains the angle of
84-
;; intersection everywhere but $$z = 0$$ (the origin). 😍
80+
;; intersection everywhere but $$z = 0$$ (the origin). 📐
81+
82+
;; It's called a conformal map by mathematicians. 😍
8583

8684
#_(clerk/show! "notebooks/logo.clj")

0 commit comments

Comments
 (0)