Public
Edited
Mar 22, 2023
Insert cell
Insert cell
// https://music.stackexchange.com/questions/93731/does-guitar-fret-spacing-solely-depend-on-the-length-of-the-string
// https://www.omnicalculator.com/other/fret
// https://www.lmii.com/blog/fret-scale-and-fingerboard-length-calculator/

// math render into object (INCLUDING RATIOS!)
// visual render
Insert cell
viewof input = Inputs.form({
text_input:"Inputs",
n_frets: Inputs.range([0,30], {label: "Number of frets", value: 21, step: 1}),
scale_length: Inputs.number([1, 1000], {label: "Scale length (mm)", value: 635, step: 1}),
fb_length: Inputs.number([1, 1000], {label: "Fretboard length (mm)", value: 500, step: 1}),
fret_ratio: Inputs.select(ratios_list,{label: "Fret ratio"}),
demo_input: "Context",
nut_offset: Inputs.number([0, 1000], {label: "Nut offset (mm)", value: 3.175}),
last_offset: Inputs.number([0, 1000], {label: "Last fret offset (mm)", value: 0}),

})
Insert cell
// generate an array with initial values
// properties: Fret num (0=nut), position (mm)
fretboard = (frets,scale,length,ratio) => {
var arr = [].push(length);
var newfret = "";
for (var i=0; i<=frets; i++){
var lastfret = newfret;
newfret = length*ratio;
arr.push(newfret);
}
return arr;
}
Insert cell
demo = fretboard(input.n_frets,input.scale_length,input.fb_length,input.fret_ratio)
Insert cell
// length of fretboard is last value on fretboard array + nut offset + last fret offset
total_length = demo[-1]+input.nut_offset+input.last_offset
Insert cell
// generate a viz
Insert cell
ratios_list = [18/17]
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more