Skip to content

Instantly share code, notes, and snippets.

@g-delmo
Created September 7, 2022 09:54
Show Gist options
  • Save g-delmo/74996871403f2aa6bcb79fb027221897 to your computer and use it in GitHub Desktop.
Save g-delmo/74996871403f2aa6bcb79fb027221897 to your computer and use it in GitHub Desktop.
Brightness thing
function rgb2hsv(r,g,b) {
let v=Math.max(r,g,b), c=v-Math.min(r,g,b);
let h= c && ((v==r) ? (g-b)/c : ((v==g) ? 2+(b-r)/c : 4+(r-g)/c));
return [60*(h<0?h+6:h), v&&c/v, v];
}
function hsv2rgb(h,s,v) {
let f= (n,k=(n+h/60)%6) => v - v*s*Math.max( Math.min(k,4-k,1), 0);
return [f(5),f(3),f(1)];
}
const makeBrighter = (r, g, b) => {
const hsvConversion = rgb2hsv(r, g, b);
if (hsvConversion[2] <= 80) {
return hsv2rgb(hsvConversion[0], hsvConversion[1], hsvConversion[2] + 100);
}
if (hsvConversion[2] <= 125) {
return hsv2rgb(hsvConversion[0], hsvConversion[1], hsvConversion[2] + 50);
}
return [r, g, b];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment