(bind-func draw_frame
  (let (
      (fill (NVGcolor 1.0 0.0 0.0 1.0))
      (stroke (NVGcolor 1.0 1.0 1.0 0.5))
      (rad (cpCircleShapeGetRadius ballShape)))
    (lambda (delta_t:double)
      (let ((pos (cpBodyGetPosition ballBody)))
        (nvgBeginFrame vg (convert width) (convert height) pixel_ratio)
        (nvgTransform vg (/ width (/ 200. pixel_ratio)) 0. 0. (/ height -200.) (/ width 2.) (* 3. (/ height 4.)))
        (nvgStrokeColor vg stroke)
        (nvgFillColor vg fill)
        (nvgStrokeWidth vg 0.25)
        (nvgBeginPath vg)
        (nvgCircle vg (convert (tref pos 0)) (convert (tref pos 1)) (convert rad))
        (draw_seg wall)
        (draw_seg ground)
        (nvgStroke vg)
        (nvgFill vg)
        (nvgEndFrame vg)
        (if (or
            (< (cpvlengthsq (cpBodyGetVelocity ballBody)) 0.1)
            (< (tref pos 1) -100.))
          (begin
            (cpBodySetPosition ballBody (cpVect_val (* (imp_randd) 50.) 100.))
            (cpBodySetVelocity ballBody (cpVect_val (* (- (imp_randd) 0.5) 5.) 0.))))
        (cpSpaceStep space delta_t)))))