   stream.on 'data', (chunk) -> out.write(chunk)
   stream.on 'end', () -> console.log "Saved #{fname}"
 
-draw_intervals_from = (semitones, root_string, root_fret, color) ->
+intervals_from = (root_string, root_fret, semitones) ->
   root_note_number = note_number_at(root_string, root_fret)
-  draw_note root_string, root_fret, true, color
+  fingerings = []
   for string in strings
     for fret in frets
       continue if string == root_string and fret == root_fret
       continue unless (note_number_at(string, fret) - root_note_number + 120) % 12 == semitones
-      draw_note string, fret, false, color
+      fingerings.push string: string, fret: fret
+  return fingerings
+
+draw_intervals_from = (semitones, root_string, root_fret, color) ->
+  root_note_number = note_number_at(root_string, root_fret)
+  draw_note root_string, root_fret, true, color
+  for {string, fret} in intervals_from(root_string, root_fret, semitones)
+    draw_note string, fret, false, color
 
 interval_cards = ->
   fingerings_each (string, fret) ->

    for ix in [0...12]
      pitch_number = (ix * 5 + 7) % 12
      fingering = pitch_fingers[pitch_number]
      string = fingering[0]
      fret = fingering[1]
      draw_cell ->
        ctx.font = '20px Impact'
        ctx.font = '5pt Times' if draw_diagrams
        ctx.fillStyle = 'rgb(10,20,30)'
        ctx.fillText note_names[pitch_number] + ' ' + title, h_gutter, -3
        draw_fingerboard()
        for semitones, si in outervals
          continue if semitones in intervals
          draw_intervals_from semitones, string, fret, other_colors[si]
        for semitones, si in intervals
          draw_intervals_from semitones, string, fret, colors[si]

# chord_page 'Major', [0, 4, 7]



chord_book = ->
  chords = [
    {name: 'Major', offsets: [0, 4, 7], relative: [0, 3, 7]},
    {name: 'Minor', offsets: [0, 3, 7], relative: [0, 4, 7]},
    {name: 'Aug', offsets: [0, 4, 8], relative: [0, 4, 7]},
    {name: 'Dim', offsets: [0, 3, 6], relative: [0, 3, 7]},
    {name: '7th', offsets: [0, 4, 7, 10]},
    {name: 'Maj7', offsets: [0, 4, 7, 11]},
    {name: 'Sus2', offsets: [0, 2, 7], relative: [0, 4, 7]},
    {name: 'Sus4', offsets: [0, 5, 7], relative: [0, 4, 7]},
    {name: 'Min7', offsets: [0, 3, 7, 10], relative: [0, 4, 7, 10]},
    {name: 'Dim7', offsets: [0, 3, 6, 9]},
    {name: '6th', offsets: [0, 4, 7, 9]},
  ]
  book "Combined Fretboard Chords.pdf", (page) ->
    for {name, offsets, relative} in chords
      page -> chord_page name, offsets, relative

chord_book()
