Hilbert curve: Difference between revisions

Content added Content deleted
Line 1,786: Line 1,786:
(for/fold ([image empty-image] [x 0] [y 0] [theta (/ pi 2)])
(for/fold ([image empty-image] [x 0] [y 0] [theta (/ pi 2)])
([cmd (in-list (get-cmds N 'A))])
([cmd (in-list (get-cmds N 'A))])
(define-values (new-x new-y new-theta)
(define-values (x* y* theta*)
(match cmd
(match cmd
['F (values (+ x (* R (cos theta)))
['F (values (+ x (* R (cos theta))) (+ y (* R (sin theta))) theta)]
(+ y (* R (sin theta)))
theta)]
['+ (values x y (+ theta (/ pi 2)))]
['+ (values x y (+ theta (/ pi 2)))]
['- (values x y (- theta (/ pi 2)))]
['- (values x y (- theta (/ pi 2)))]
[_ (values x y theta)]))
[_ (values x y theta)]))
(values (add-line image x y new-x new-y the-pen)
(values (add-line image x y x* y* the-pen) x* y* theta*)))
new-x new-y new-theta)))


(overlay image (empty-scene (+ OFFSET (image-width image))
(overlay image (empty-scene (+ OFFSET (image-width image))