# Moiré Patterns: Square and Hexagon

Overlaid hexagon grids with moderate rotational offset

A square grid with a slight rotational offset gives a square or diamond zig-zag grid:

With smaller squares, the checkerboard pattern is more interesting:

Hexagonal grids give an interesting variety of overlap patterns in one image:

The new code is below:

``````;; Copyright 2021 Christopher Howard

;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at

;; Unless required by applicable law or agreed to in writing, software
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and

(define* (draw-square-block r orig-x orig-y base-l
#:key (rotr 0))
(let* ((lrot (if (zero? rotr) (lambda (x) x)
(lambda (c) (rot rotr c))))
(ccomp (lambda (c) (cex (lrot c)))))
(render-draw-lines
r
(map ccomp (list (list orig-x orig-y)
(list (+ orig-x base-l) orig-y)
(list (+ orig-x base-l) (+ orig-y base-l)))))))

(define* (draw-square-pattern r offset-x offset-y #:key (rotr 0))
(let* ((base-l 10))
(do ((j 0 (1+ j)))
((> j 80))
(do ((i 0 (1+ i)))
((> i 80))
(draw-square-block
r
(+ (* i base-l) offset-x)
(+ (* j base-l) offset-y)
base-l
#:rotr rotr)))))

(define* (draw-hexagon-block r orig-x orig-y base-l
#:key (rotr 0))
(let* ((base-hl (* 0.5 base-l))
(base-h (* (* base-l (sqrt 3)) 0.5))
(lrot (if (zero? rotr) (lambda (x) x)
(lambda (c) (rot rotr c))))
(ccomp (lambda (c) (cex (lrot c)))))
(render-draw-lines
r
(map ccomp (list (list orig-x orig-y)
(list (- orig-x base-hl)
(+ orig-y base-h))
(list orig-x
(+ orig-y (* 2 base-h)))
(list (+ orig-x base-l)
(+ orig-y (* 2 base-h)))
(list (+ orig-x base-l base-hl)
(+ orig-y base-h))
(list (+ orig-x base-l)
orig-y))))
(render-draw-lines
r
(map ccomp (list (list (- orig-x base-hl)
(+ orig-y base-h))
(list (- orig-x base-hl base-l)
(+ orig-y base-h)))))))

(define* (draw-hexagon-pattern r offset-x offset-y #:key (rotr 0))
(let* ((base-l 20)
(base-h (* (* base-l (sqrt 3)) 0.5))
(base-hl (* 0.5 base-l)))
(do ((j 0 (1+ j)))
((> j 40))
(do ((i 0 (1+ i)))
((> i 40))
(draw-hexagon-block
r
(+ offset-x
(* i 3 base-l))
(+ offset-y (* j 2 base-h))
base-l
#:rotr rotr)))))``````