Skip to content

Instantly share code, notes, and snippets.

@cyrilmottier
Created June 25, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyrilmottier/fba31e86155a9506d38a0053738a8fe7 to your computer and use it in GitHub Desktop.
Save cyrilmottier/fba31e86155a9506d38a0053738a8fe7 to your computer and use it in GitHub Desktop.
val colorCount = RAINBOW_COLORS.size
val colors = IntArray(colorCount * 2)
val stops = FloatArray(colorCount * 2)
for (i in 0 until colorCount) {
colors[i * 2] = ContextCompat.getColor(context, RAINBOW_COLORS[i])
colors[i * 2 + 1] = colors[i * 2]
stops[i * 2] = (i / colorCount.toFloat() + RAINBOW_EPSILON).coerceAtLeast(0f)
stops[i * 2 + 1] = ((i + 1) / colorCount.toFloat() - RAINBOW_EPSILON).coerceAtMost(1f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment