Skip to content

Instantly share code, notes, and snippets.

@PramodGarg
Created May 20, 2020 08:07
Show Gist options
  • Save PramodGarg/49ac161b456bd5399b5c329891b4782c to your computer and use it in GitHub Desktop.
Save PramodGarg/49ac161b456bd5399b5c329891b4782c to your computer and use it in GitHub Desktop.
fun addAlphaToColor(originalColor: String, alpha: Float): String {
val alphaFixed = (alpha * 255).roundToLong()
var alphaHex = java.lang.Long.toHexString(alphaFixed)
if (alphaHex.length == 1) {
alphaHex = "0$alphaHex"
}
return originalColor.replace("#", "#$alphaHex")
}
fun getColorPalletWithAlpha(color: String, numberOfColors: Int, minAlpha: Float = 0.15f,
maxAlpha: Float = 1f): List<String> {
val delta = (maxAlpha - minAlpha) / numberOfColors
val list = mutableListOf<String>()
for (i in 1..numberOfColors) {
list.add(addAlphaToColor(color, i * delta))
}
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment