leanny.github.io
leanny.github.io copied to clipboard
Feature request: Hex color formatter
https://github.com/Leanny/leanny.github.io/blob/1798cfd02541c0684c29108bd68415881067ea95/splat3/js/Utility.js#L350
Hi Lean, is it possible to have a dynamic color_formatter that takes the colors and prints the hex value if desired? Or maybe add to the existing one?
function rgbaToVal(redF, greenF, blueF, alphaF = 1.0) {
let redInt = 255.0 * redF;
let greenInt = 255.0 * greenF;
let blueInt = 255.0 * blueF;
let alphaInt = 255.0 * alphaF;
let colorVal = ((alphaInt & 0xFF) << 24) | ((redInt & 0xFF) << 16) | ((greenInt & 0xFF) << 8) | (blueInt & 0xFF);
colorVal = colorVal >>> 0; // Make uint
return colorVal;
}
function rgbaToHex(redF, greenF, blueF, alphaF = 1.0) {
let colorVal = rgbaToVal(redF, greenF, blueF, alphaF);
// console.log("ARGB: 0x" + colorVal.toString(16).toUpperCase());
return "#" + colorVal.toString(16); // e.g. #ff112233
}