about summary refs log tree commit diff stats
path: root/319timer.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-05 23:18:30 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-05 23:18:30 -0700
commitcbf22e7ab205fc935b8b03ef50205adb4106d8e4 (patch)
treec88c80fd14b5a445d4e3ede34f92a8097f3ba398 /319timer.subx
parent468b0d979fe2e20f146d19934d22ccb566c04d9d (diff)
downloadmu-cbf22e7ab205fc935b8b03ef50205adb4106d8e4.tar.gz
primitives for double-buffering
I thought I needed these for this bouncing-ball demo:

  def (bounce screen)
    with (w (width screen)
          h (height screen)
          cx 16
          cy 16
          dx 12
          dy 19)
      while 1
        clear screen
        ring screen cx cy 16 3 5
        cx += dx
        cy += dy
        when (or (cx > w) (cx < 0))
          set dx 0-dx
        when (or (cy > h) (cy < 0))
          set dy 0-dy
        for _ 0 (< _ 100) ++_         # delay

No matter how I adjusted the delay I couldn't get rid of the jitter. So
I built a double-buffered version:

    (bounce2 . [def (bounce2 screen)
  with (w (width screen)
        h (height screen)
        cx 16
        cy 16
        dx 12
        dy 19
        screen2 (new_screen (columns screen)
                            (lines screen)))
      while 1
        clear screen2
        ring screen2 cx cy 16 3 5
        cx += dx
        cy += dy
        when (or (cx > w) (cx < 0))
          set dx 0-dx
        when (or (cy > h) (cy < 0))
          set dy 0-dy
        blit screen2 screen
        for _ 0 (< _ 100) ++_])       # delay

But it didn't make a difference! Turns out nothing will help you when
successive frames are too far apart. This is the correct tweak to
`bounce`:

  -       dx 12
  -       dy 19)
  +       dx 1
  +       dy (/ 19 12))

Still, we'll keep double-buffering around for the future.
Diffstat (limited to '319timer.subx')
0 files changed, 0 insertions, 0 deletions