Skip to content

Instantly share code, notes, and snippets.

@rmloveland
Created June 16, 2020 19:43
Show Gist options
  • Save rmloveland/43d11c2107139cd68a28f64cde46aff6 to your computer and use it in GitHub Desktop.
Save rmloveland/43d11c2107139cd68a28f64cde46aff6 to your computer and use it in GitHub Desktop.
(define (hilbert order width)
(let loop ((count 0)
(shape (h0 width)))
(if (= count order)
shape
(let* ((next-shape (shrink-shape shape 0.5))
(upper-left (reflect-shape (rotate-shape next-shape (* 3.14159 1.5))))
(upper-right (translate-shape next-shape 'east width))
(lower-left (translate-shape next-shape 'south width))
(lower-left* (reflect-shape (rotate-shape lower-left (* 3.14159 .5))))
(lower-right (translate-shape next-shape 'southeast width)))
(loop (+ count 1)
(merge-shapes upper-left upper-right lower-right lower-left*))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment