|
39 | 39 | (c2d/set-background 255 255 255)
|
40 | 40 | (c2d/set-color 66 66 66)
|
41 | 41 | (c2d/set-stroke 4)
|
42 |
| - (c2d/path hilbert-points)) |
43 |
| - ;; just the underlying BufferedImage, please |
44 |
| - (c2d/to-image canvas)) |
| 42 | + (c2d/path hilbert-points) |
| 43 | + c2d/to-image)) |
45 | 44 |
|
46 | 45 | ;; The trick to getting the effect we want is to apply a conformal
|
47 | 46 | ;; mapping to the original Hilbert Curve to convert it into an 👁 shape
|
48 | 47 | ;; in celebration of Clerk's viewers. We can do this by treating the
|
49 |
| -;; original point coordinates as complex numbers, |
50 |
| -;; squaring them, then taking the real and imaginary portions of each |
51 |
| -;; of those complex numbers as the _x_ and _y_ coordinates of a new |
52 |
| -;; set of points. This is made especially easy because Clojure2D |
53 |
| -;; happens to include the author's |
54 |
| -;; [Fastmath](https://github.com/generateme/fastmath) library. |
| 48 | +;; original point coordinates as complex numbers, squaring them, then |
| 49 | +;; taking the real and imaginary portions of each of those complex |
| 50 | +;; numbers as the _x_ and _y_ coordinates of a new set of points. This |
| 51 | +;; is made especially easy because Clojure2D happens to include the |
| 52 | +;; author's [Fastmath](https://github.com/generateme/fastmath) |
| 53 | +;; library. 🎉 |
55 | 54 |
|
56 | 55 | (c2d/with-canvas [canvas (c2d/canvas 1000 600 :highest)]
|
57 | 56 | (-> canvas
|
58 |
| - (c2d/set-background 33.0 5.0 24.0) |
59 |
| - (c2d/translate 500 300) ; origin to center |
60 |
| - (c2d/rotate (/ Math/PI 2)) ; rotate canvas around origin |
| 57 | + (c2d/set-background 33.0 5.0 24.0) ; RGB deep purple |
| 58 | + (c2d/translate 500 300) ; origin to center |
| 59 | + (c2d/rotate (/ Math/PI 2)) ; rotate the canvas, ⬯ → ⬭ |
61 | 60 | ;; colour and stroke width
|
62 | 61 | (c2d/set-color 147.0 189.0 154.0)
|
63 | 62 | (c2d/set-stroke 4)
|
64 | 63 | ;; ellipses to fill in the center of the "eye"
|
65 | 64 | (c2d/ellipse 0 0 22 22)
|
66 | 65 | (c2d/ellipse 0 -10 20 20)
|
67 | 66 | (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)) |
| 67 | + ;; draw a path using the complex square of our hilbert curve points |
| 68 | + (c2d/path (map #(-> (v/sub % (v/vec2 400 400)) ; -[½w ½h] from vectors to center the curve |
| 69 | + complex/sq ; square each vector as a complex number |
| 70 | + (v/mult 0.0015)) ; scale those squared vectors down |
| 71 | + hilbert-points)) |
| 72 | + c2d/to-image)) |
77 | 73 |
|
78 | 74 | ;; What I find so special and enchanting about the $$w = z^{2}$$
|
79 | 75 | ;; mapping that we're using here is that it maintains the angle of
|
80 | 76 | ;; intersection everywhere but $$z = 0$$ (the origin). 📐
|
81 | 77 |
|
82 |
| -;; It's called a conformal map by mathematicians. 😍 |
| 78 | +;; This is called a _conformal map_ by mathematicians. 😍 |
83 | 79 |
|
84 | 80 | #_(clerk/show! "notebooks/logo.clj")
|
0 commit comments