Last active
August 22, 2019 19:49
-
-
Save IMoHaMeDHaMdYI/dda95079ae7cb02e2d494084aa5183a3 to your computer and use it in GitHub Desktop.
Discovering RadialGradient
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
// With the assumption, this code is written inside a view | |
// choose a reasonable range of colors, some ranges won't be drawn and I don't know why actually. | |
private val shadowStartColor = 0x99ffffff.toInt() | |
private val shadowEndColor = 0x03ffffff | |
private val shadowSize = 50f | |
val radialGradientPaint =RadialGradient(centerX | |
, centerY, | |
radius, | |
intArrayOf(shadowStartColor, shadowEndColor), | |
floatArrayOf(0f, 1f), | |
Shader.TileMode.CLAMP).apply { | |
isAntiAlias = true | |
strokeJoin = Paint.Join.ROUND | |
style = Paint.Style.FILL | |
val mn = min(width, height) | |
shader = RadialGradient(width / 2f, height / 2f, mn.toFloat(), intArrayOf(shadowStartColor, shadowEndColor), floatArrayOf(0f, 1f), Shader.TileMode.CLAMP) | |
isDither = true | |
} | |
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
canvas.drawOval(RectF(0f, 0f, width, height), radialGradientPaint) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment