improved vector management added by Corbin on Tue Oct 12 22:19:23 2021

(define ((draw-pixel program vp) i)
  (let*
    ((color (program (vp i)))
     (r (car color))
     (g (car (cdr color)))
     (b (cdr (cdr color))))
    (list->u8vector (map finish-channel (list r g b)))))

(define ((draw-png program width height))
  (let*
    ((vp (viewport width height))
     (drawable (draw-pixel program vp))
     (size (* width height))
     (channels 3)
     (pixels
       (do ((buf (make-u8vector (* size channels)))
            (i 0 (+ i 1)))
         ((eqv? i size) buf)
         (u8vector-copy! buf (* i channels) (drawable i)))))
    (write-png pixels width height channels)))