mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
first commit
This commit is contained in:
23
_ext/scripts/utilities/rgbToHex.js
Normal file
23
_ext/scripts/utilities/rgbToHex.js
Normal file
@ -0,0 +1,23 @@
|
||||
//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);
|
||||
}
|
Reference in New Issue
Block a user