Draw chord just calling chord("C"), chord("c"), chord("F") and options on the fret.
require "gd"
img = GD::Image.new(520, 640)
white = GD::Color.rgb(255,255,255)
black = GD::Color.rgb(0,0,0)
gray = GD::Color.rgb(80,80,80)
img.fill(white)
left = 60
right = 460
top = 140
bottom = 580
strings = 6
frets = 5
string_gap = (right - left) / (strings - 1).to_f
fret_gap = (bottom - top) / frets.to_f
# ----------------------
# Title
# ----------------------
img.text("C", {
x: 230,
y: 50,
size: 40,
color: black,
font: "./DejaVuSans.ttf"
})
# ----------------------
# Strings (vertical)
# ----------------------
strings.times do |i|
x = (left + i * string_gap).to_i
img.line(x, top, x, bottom, gray)
end
# ----------------------
# Frets (horizontal)
# ----------------------
(0..frets).each do |f|
y = (top + f * fret_gap).to_i
if f == 0
img.filled_rectangle(left - 3, y - 3, right + 3, y + 3, black)
else
img.line(left, y, right, y, gray)
end
end
# ----------------------
# X / O labels x32010
# ----------------------
labels = ["X", "3", "2", "0", "1", "0"]
labels.each_with_index do |lab, i|
x = (left + i * string_gap).to_i - 6
img.text(lab, {
x: x,
y: top - 55,
size: 30,
color: black,
font: "./DejaVuSans.ttf"
}) if ["X", "0"].include?(lab)
end
# ----------------------
# Finger dots
# ----------------------
dots = [
{ string: 1, fret: 3 }, # A string
{ string: 2, fret: 2 }, # D
{ string: 4, fret: 1 } # B
]
dots.each do |d|
x = (left + d[:string] * string_gap).to_i
y = (top + (d[:fret] - 0.5) * fret_gap).to_i
img.filled_ellipse(x, y, 28, 28, black)
end
# ----------------------
# Fret numbers
# ----------------------
(1..frets).each do |f|
y = (top + (f - 0.5) * fret_gap).to_i - 6
img.text(f.to_s, {
x: left - 35,
y: y,
size: 20,
color: black,
font: "./DejaVuSans.ttf"
})
end
img.save("chord_C.png")
What problem are you trying to solve?
Draw chord just calling chord("C"), chord("c"), chord("F") and options on the fret.
How would you like the API to look?
Use case