Skip to content

Instantly share code, notes, and snippets.

@twyatt
Created September 28, 2017 05:41
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 twyatt/a236ac36f841a847501eba66a230460e to your computer and use it in GitHub Desktop.
Save twyatt/a236ac36f841a847501eba66a230460e to your computer and use it in GitHub Desktop.
typealias ColorFunction = (currentTimeMillis: Long) -> Int
class CustomView : View {
val paint = Paint()
var colorFunction: ColorFunction? = null
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val cx = width / 2f
val cy = height / 2f
val radius = Math.min(cx, cy)
paint.color = colorFunction?.invoke(System.currentTimeMillis())
canvas.drawCircle(cx, cy, radius, paint)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment