JSFiddle - React, Tailwind, and code Playground
by Peter Hozák
JavaScript
width_px = 500
function frequencty_to_px(frequency) {
var min_f = Math.log(20) / Math.log(10),
max_f = Math.log(16000) / Math.log(10),
range = max_f - min_f,
position_px = (Math.log(frequency) / Math.log(10) - min_f) / range * width_px
return frequency + " Hz => " + position_px + " px"
}
document.write(frequencty_to_px(20) + "<br />")
document.write(frequencty_to_px(500) + "<br />")
document.write(frequencty_to_px(15000) + "<br />")
document.write(frequencty_to_px(16000) + "<br />")