created ShadeMyCanvas (smc)

This commit is contained in:
do butterflies cry? 2026-02-02 01:12:53 +10:00
parent 935cc44f66
commit 1d06470ccd
12 changed files with 539 additions and 24 deletions

24
www/js/smc/util.js Normal file
View file

@ -0,0 +1,24 @@
export { hexToRgba, hexToRgbaNormal };
/* Converts a string of the form "#XXXXXX"
*
*/
function hexToRgba(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex.toLowerCase());
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
a: result.length == 4 ? parseInt(result[4], 16) : 255.,
} : null;
}
function hexToRgbaNormal(hex) {
var result = hexToRgba(hex);
return result ? {
r: result.r / 255.,
g: result.g / 255.,
b: result.b / 255.,
a: result.a / 255.,
} : null;
}