mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
24 lines
556 B
JavaScript
24 lines
556 B
JavaScript
//convert rgb values to a hex string for html
|
|
function rgbToHex (argument0,g,b) {
|
|
var r;
|
|
|
|
//if the first argument is an object
|
|
if (typeof argument0 === 'object'){
|
|
r = argument0.r;
|
|
g = argument0.g;
|
|
b = argument0.b;
|
|
}
|
|
else
|
|
r = argument0;
|
|
|
|
//console.log('converting rgb('+r+','+g+','+b+') to hex');
|
|
|
|
//convert a decimal number to 2-digit hex
|
|
function componentToHex (c) {
|
|
var hex = c.toString(16);
|
|
return hex.length == 1 ? "0" + hex : hex;
|
|
}
|
|
|
|
return componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
}
|