Skip to content

Instantly share code, notes, and snippets.

@astynax
Created September 17, 2018 19:19
Show Gist options
  • Save astynax/dca68019f3fcedeab99c8ba8eafe39fb to your computer and use it in GitHub Desktop.
Save astynax/dca68019f3fcedeab99c8ba8eafe39fb to your computer and use it in GitHub Desktop.
Carpet-like pattern
#lang racket
(require 2htdp/image)
(define (->color c)
(cond [(= c 0) 'indigo]
[(= c 1) 'palevioletred]
[(= c 2) 'moccasin]
[else 'white]))
(define (next-c c) (modulo (+ 1 c) 4))
(define (i c s)
(if (< s 5)
(square s 'solid (->color c))
(overlay (rotate 45 (i (next-c c) (* 0.707 s)))
(square s 'solid (->color c)))))
(define (sq2x2 i1 i2)
(above (beside i1 i2)
(beside i2 i1)))
(define (step c s)
(if (< s 10) (i (next-c c) (* 1.2 s))
(sq2x2 (step (next-c c) (/ s 2)) (i c (* 0.707 s)))))
(step 0 400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment