Leanny / leanny.github.io

156 stars 38 forks source link

Feature request: Hex color formatter #171

Closed kjhf closed 2 years ago

kjhf commented 2 years ago

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
}
Leanny commented 2 years ago

Thank you very much. I push it with the next update. The result looks like this

grafik

kjhf commented 2 years ago

Thanks :)