I have RGB colors in the form:
[0.00784, 0.62745, 0.77647]
I would like to convert them to hex color, but I'm not sure how. I've seen other types of RGB components converted to hex, but not in this format.
I have RGB colors in the form:
[0.00784, 0.62745, 0.77647]
I would like to convert them to hex color, but I'm not sure how. I've seen other types of RGB components converted to hex, but not in this format.
Multiply all the values by 255, round it and then use the solution from this question.
const componentToHex = c => {
const hex = c.toString(16)
return hex.length === 1 ? '0' + hex : hex
}
const rgbToHex = (r, g, b) => '#' + [r, g, b].map(componentToHex).join('')
const rgb = [0.00784, 0.62745, 0.77647].map(x => Math.round(x * 255))
console.log(rgbToHex(...rgb))