Index / 2018-09-29-square-petals.rkt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#lang racket
(require 2htdp/image)

(define (->color x)
  (list-ref '(Indigo
              BlueViolet
              Thistle
              LavenderBlush)
            (modulo x 4)))

(define (step i l f s)
  (if (< s 20)
      (i l s)
      (let* ([s2 (/ s 2)]
             [ii (step i (+ l 1) (not f) s2)]
             [ri (rotate 90 ii)]
             [li (if f (rotate 180 ii)
                     (square s2 0 'White))])
        (overlay (above (beside li ri)
                        (beside ri li))
                 (i l s)))))

(define (item l s)
  (overlay (circle (/ s 6) 120 'White)
           (square (/ s 2) 'outline 'Black)
           (square (/ s 2) 200 (->color l))
           (square s 0 'White)))

(provide main)
(define (main . args)
  (save-image
   (step item 0 #t 600)
   (car args)))