Daily art: 2019-10-01-phytoplankton.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 (item s f)
  (let ([corner (underlay
                 (circle (* 0.6 s) 'solid 'GreenYellow)
                 (circle (* 0.4 s) 'solid (if f 'ForestGreen 'Black)))])
    (place-image
     corner s s
     (place-image
      (rotate 180 corner) 0 0
      (square s 'solid (if f 'Black 'ForestGreen))))))

(define (block s)
  (let* ([i (λ (f) (item s f))]
         [r (λ (f) (flip-horizontal (i f)))])
    (overlay
     (circle (* 0.2 s) 'solid 'yellow)
     (above (beside (i #t) (r #t))
            (beside (r #t) (r #f))))))

(define (step i f s)
  (if (< s 80)
      (rotate (if f 0 180) (i s))
      (let ([ii (λ (x) (step i (not x) (/ s 2)))])
        (above (beside (rotate (if f   0 -90) (ii (not f)))
                       (rotate (if f   0 180) (ii      f)))
               (beside (rotate (if f  90   0) (ii (not f)))
                       (rotate (if f -90   0) (ii      f)))))))

(save-image
 (step block #t 400)
 "output.png")