Created
September 7, 2020 07:02
-
-
Save noudadrichem/a638f7dd74254aee146d022a56e749bf to your computer and use it in GitHub Desktop.
Gives back tags based on RGB code if it's light or dark
This file contains 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
public isColourDarkOrLight(rgb: number[]): 'light' | 'dark' { | |
// RGB to HSP equation: http://alienryderflex.com/hsp.html | |
const [r, g, b] = rgb; | |
const hsp = Math.sqrt( | |
0.299 * (r * r) + | |
0.587 * (g * g) + | |
0.114 * (b * b) | |
); | |
return hsp > 127.5 ? 'light' : 'dark'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment