Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created October 29, 2024 10:26
Show Gist options
  • Save KatieBarnett/95ed365619d5846ba5cae38afcf4cf28 to your computer and use it in GitHub Desktop.
Save KatieBarnett/95ed365619d5846ba5cae38afcf4cf28 to your computer and use it in GitHub Desktop.
fun colorIsDarkAdvanced(bgColor: Int): Boolean {
// hexToB
val uicolors = doubleArrayOf(
bgColor.red.toDouble() / 255.0,
bgColor.green.toDouble() / 255.0,
bgColor.blue.toDouble() / 255.0
)
val c = uicolors.map { col ->
if (col <= 0.03928) {
col / 12.92
} else {
Math.pow((col + 0.055) / 1.055, 2.4)
}
}
val L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]
return L <= 0.179
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment