|
33 | 33 |
|
34 | 34 | ;; But they're much more interesting if we use
|
35 | 35 | ;; [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: |
37 | 37 | (c2d/with-canvas [canvas (c2d/canvas 800 800 :highest)]
|
38 | 38 | (-> canvas
|
39 | 39 | (c2d/set-background 255 255 255)
|
40 | 40 | (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)) |
44 | 43 | ;; just the underlying BufferedImage, please
|
45 |
| - (:buffer canvas)) |
| 44 | + (c2d/to-image canvas)) |
46 | 45 |
|
47 | 46 | ;; The trick to getting the effect we want is to apply a conformal
|
48 | 47 | ;; 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, |
51 | 50 | ;; squaring them, then taking the real and imaginary portions of each
|
52 | 51 | ;; of those complex numbers as the _x_ and _y_ coordinates of a new
|
53 | 52 | ;; set of points. This is made especially easy because Clojure2D
|
|
65 | 64 | ;; ellipses to fill in the center of the "eye"
|
66 | 65 | (c2d/ellipse 0 0 22 22)
|
67 | 66 | (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)) |
81 | 77 |
|
82 | 78 | ;; What I find so special and enchanting about the $$w = z^{2}$$
|
83 | 79 | ;; 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. 😍 |
85 | 83 |
|
86 | 84 | #_(clerk/show! "notebooks/logo.clj")
|
0 commit comments