Skip to content

Instantly share code, notes, and snippets.

@IMoHaMeDHaMdYI
Last active August 22, 2019 19:49
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 IMoHaMeDHaMdYI/dda95079ae7cb02e2d494084aa5183a3 to your computer and use it in GitHub Desktop.
Save IMoHaMeDHaMdYI/dda95079ae7cb02e2d494084aa5183a3 to your computer and use it in GitHub Desktop.
Discovering RadialGradient
// 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