Created
September 7, 2022 09:54
-
-
Save g-delmo/74996871403f2aa6bcb79fb027221897 to your computer and use it in GitHub Desktop.
Brightness thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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