   speed ||= (if quick then 10 else 1)
   chord = Chords[0]
   title = "#{chord.name} Chord Shapes"
+  just_one = false
 
   with_animation_context
     title: "Chord Shape Animation Frames"


ease = (s, x0, x1) ->x0 + s * (x1 - x0)

easeAttr = (path, aname, s, defaultValue) ->
  return defaultValue unless path and aname of path[0]
  ease(s, path[0][aname], path[1][aname])

sprite_position_at = (sprite, t) ->
  s = Math.min(1, (t - sprite.t0) / (sprite.t1 - sprite.t0))
  s = Math.min(1, t - sprite.t0) unless 't1' of sprite
  {
    x: easeAttr(sprite.path, 'x', s, 0)
    y: easeAttr(sprite.path, 'y', s, 0)
  }

write_animation_frames = (options) ->
  {step_size, sprites, end_padding} = options
  step_size ||= 1
  t_end = Math.max(_.chain(sprites).pluck('t1').compact().value()...)
  t_end += (end_padding or 0)
  t = 0
  with_book (options.title || "animation frames"), (book) ->
    ctx = book.context
    while t < t_end
      book.add_page ->
        with_page width: 640, height: 480, ->
          current_sprites = (sprite for sprite in sprites when (sprite.t0 or 0) <= t < (sprite.t1 or t_end))
          for sprite in _.sortBy(current_sprites, (s) -> (s.z_index or 0))
            s = Math.min(1, (t - sprite.t0) / (sprite.t1 - sprite.t0))
            s = t - sprite.t0 unless sprite.t1
            {x, y} = sprite_position_at(sprite, t)
            with_graphics_context (ctx) ->
              ctx.translate x, y
              sprite.draw ctx, s

        sprite.at 1, x: 400, y: 50

    animation.make_sprite
      visible: not just_one
      draw: ->
        draw_title title
        , font: '20px Impact', fillStyle: 'rgb(128, 128, 128)'
        , gravity: 'top'

    [0...12].forEach (i) ->
      return if i > 0 and just_one
      t0 = pitch = i
      chord_name = compute_chord_name pitch, chord
      name = "#{chord_name} Major"
      fingering = best_fingering_for chord, pitch
      pos = sprite_position_at master_diagram, t0
      [col, row] = [i % 4 , Math.floor(i / 4)]

      animation.make_sprite
        name: name
        t0: t0
        draw: (ctx, dt) ->
          draw_title name, font: '12pt Times', fillStyle: 'black', y: -3
          draw_chord_diagram ctx, fingering.positions, barres: fingering.barres

      , (sprite) ->
        # sprite.at t0, visible: true
        sprite.at 0, pos
        sprite.at 0.5, pos
        # sprite.at 1, pos
        sprite.at 1, x: 50 + col * 130, y: pos.y + 100 + row * 115

module.exports = chord_shape_flipbook
