1556 Biomorphs

;; main will render a Dawkin's Biomorph
(render)

;; render a segment at 0, 0 with a length along the positive x axis
;;
(fn (segment angle: 0.1
             length: 100
             colour: (col/rgb r: 0.0 g: 0.0 b: 0.3 alpha: 1.0))
  (rotate angle: angle)
  (rect position: [(/ length 2) 0]
        width: length
        height: {5 (gen/int min: 2 max: 30)}
        colour: colour)
  ;; translate to start the next segment at the end of this one
  (translate vector: [length 0]))

;; render-half is a series of segments which will have differing
;; lengths and angles
;;
(fn (render-half)
  (segment length: {30 (gen/int max: 100)} angle: {101 (gen/scalar max: 360)})
  (segment length: {43 (gen/int max: 100)} angle: {02 (gen/scalar max: 360)})
  (segment length: {73 (gen/int max: 100)} angle: {211 (gen/scalar max: 360)})
  (segment length: {33 (gen/int max: 100)} angle: {21 (gen/scalar max: 360)})
  (segment length: {13 (gen/int max: 100)} angle: {106 (gen/scalar max: 360)})
  (segment length: {03 (gen/int max: 100)} angle: {302 (gen/scalar max: 360)})
  (segment length: {43 (gen/int max: 100)} angle: {26 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {108 (gen/scalar max: 360)})
  (segment length: {43 (gen/int max: 100)} angle: {102 (gen/scalar max: 360)})
  (segment length: {83 (gen/int max: 100)} angle: {31 (gen/scalar max: 360)})
  (segment length: {63 (gen/int max: 100)} angle: {204 (gen/scalar max: 360)})
  (segment length: {93 (gen/int max: 100)} angle: {108 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {14 (gen/scalar max: 360)})
  (segment length: {34 (gen/int max: 100)} angle: {308 (gen/scalar max: 360)})
  (segment length: {53 (gen/int max: 100)} angle: {102 (gen/scalar max: 360)})
  (segment length: {33 (gen/int max: 100)} angle: {213 (gen/scalar max: 360)})
  (segment length: {73 (gen/int max: 100)} angle: {34 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {104 (gen/scalar max: 360)})
  (segment length: {53 (gen/int max: 100)} angle: {217 (gen/scalar max: 360)})
  (segment length: {63 (gen/int max: 100)} angle: {09 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {301 (gen/scalar max: 360)})
  (segment length: {93 (gen/int max: 100)} angle: {21 (gen/scalar max: 360)})
  (segment length: {53 (gen/int max: 100)} angle: {123 (gen/scalar max: 360)})
  (segment length: {43 (gen/int max: 100)} angle: {12 (gen/scalar max: 360)})
  (segment length: {33 (gen/int max: 100)} angle: {015 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {037 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {212 (gen/scalar max: 360)})
  (segment length: {63 (gen/int max: 100)} angle: {38 (gen/scalar max: 360)})
  (segment length: {93 (gen/int max: 100)} angle: {114 (gen/scalar max: 360)})
  (segment length: {23 (gen/int max: 100)} angle: {300 (gen/scalar max: 360)}))

;; render the Biomorph as 2 symmetrical halves
(fn (render)
  (on-matrix-stack
    (translate vector: [(/ canvas/width 2) (/ canvas/height 2)])
    (repeat/symmetry-vertical fn: (address-of render-half))))