Skip to content

Instantly share code, notes, and snippets.

@cyrilmottier
Created June 25, 2018 16:54
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/5082114dd684fa204ab5165bcd4cf2bd to your computer and use it in GitHub Desktop.
Save cyrilmottier/5082114dd684fa204ab5165bcd4cf2bd to your computer and use it in GitHub Desktop.
return object : Drawable() {
private val paint = Paint()
init {
val scaledWidth = RAINBOW_WIDTH * context.resources.displayMetrics.density
val y1 = (Math.sin(2 * RAINBOW_ANGLE) / 2 * scaledWidth).toFloat()
val x1 = (scaledWidth - Math.tan(RAINBOW_ANGLE) * y1).toFloat()
paint.shader = LinearGradient(
0f, 0f,
x1, y1,
colors, stops,
Shader.TileMode.REPEAT
)
}
override fun draw(canvas: Canvas) {
canvas.drawRect(bounds, paint)
}
override fun setAlpha(alpha: Int) {}
override fun getOpacity() = PixelFormat.OPAQUE
override fun setColorFilter(colorFilter: ColorFilter?) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment