Skip to content

Commit 21716c0

Browse files
authored
Merge pull request #14 from genmeblog/main
use with-canvas->
2 parents 27796d4 + e3f5406 commit 21716c0

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

notebooks/logo.clj

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
;; But they're much more interesting if we use
3535
;; [Clojure2D](https://github.com/Clojure2D/clojure2d) canvas to draw
3636
;; a path made from points to show the complete curve:
37-
(c2d/with-canvas [canvas (c2d/canvas 800 800 :highest)]
38-
(-> canvas
39-
(c2d/set-background 255 255 255)
40-
(c2d/set-color 66 66 66)
41-
(c2d/set-stroke 4)
42-
(c2d/path hilbert-points)
43-
c2d/to-image))
37+
(c2d/with-canvas-> (c2d/canvas 800 800 :highest)
38+
(c2d/set-background 255 255 255)
39+
(c2d/set-color 66 66 66)
40+
(c2d/set-stroke 4)
41+
(c2d/path hilbert-points)
42+
c2d/to-image)
4443

4544
;; The trick to getting the effect we want is to apply a conformal
4645
;; mapping to the original Hilbert Curve to convert it into an 👁 shape
@@ -52,24 +51,23 @@
5251
;; author's [Fastmath](https://github.com/generateme/fastmath)
5352
;; library. 🎉
5453

55-
(c2d/with-canvas [canvas (c2d/canvas 1000 600 :highest)]
56-
(-> canvas
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, ⬯ → ⬭
60-
;; colour and stroke width
61-
(c2d/set-color 147.0 189.0 154.0)
62-
(c2d/set-stroke 4)
63-
;; ellipses to fill in the center of the "eye"
64-
(c2d/ellipse 0 0 22 22)
65-
(c2d/ellipse 0 -10 20 20)
66-
(c2d/ellipse 0 10 20 20)
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))
54+
(c2d/with-canvas-> (c2d/canvas 1000 600 :highest)
55+
(c2d/set-background 33.0 5.0 24.0) ; RGB deep purple
56+
(c2d/translate 500 300) ; origin to center
57+
(c2d/rotate (/ Math/PI 2)) ; rotate the canvas, ⬯ → ⬭
58+
;; colour and stroke width
59+
(c2d/set-color 147.0 189.0 154.0)
60+
(c2d/set-stroke 4)
61+
;; ellipses to fill in the center of the "eye"
62+
(c2d/ellipse 0 0 22 22)
63+
(c2d/ellipse 0 -10 20 20)
64+
(c2d/ellipse 0 10 20 20)
65+
;; draw a path using the complex square of our hilbert curve points
66+
(c2d/path (map #(-> (v/sub % (v/vec2 400 400)) ; -[½w ½h] from vectors to center the curve
67+
complex/sq ; square each vector as a complex number
68+
(v/mult 0.0015)) ; scale those squared vectors down
69+
hilbert-points))
70+
c2d/to-image)
7371

7472
;; What I find so special and enchanting about the $$w = z^{2}$$
7573
;; mapping that we're using here is that it maintains the angle of

0 commit comments

Comments
 (0)