Skip to content

Instantly share code, notes, and snippets.

@vorobeij
Created February 25, 2019 09:05
Show Gist options
  • Save vorobeij/a980c1273610392342b2651fb6ef4874 to your computer and use it in GitHub Desktop.
Save vorobeij/a980c1273610392342b2651fb6ef4874 to your computer and use it in GitHub Desktop.
squirqle bezier curve
private inline fun drawBadgeSquirqle(canvas: Canvas) {
val badgeText = badge.toString()
badgeTextPaint.textScaleX = absCos(animFloat.value * Math.PI)
badgeTextPaint.getTextBounds(badgeText, 0, badgeText.length, badge.drawRect)
val cx = centerX + iconHalf
val cy = centerY - iconHalf
val w = badge.drawRect.width() * 0.9f
val h = badge.drawRect.height() * 0.9f
val left = cx - w
val right = cx + w
val top = cy - h
val bottom = cy + h
with(badgePath) {
reset()
moveTo(left, cy)
cubicTo(
left, top,
left, top,
cx, top
)
cubicTo(
right, top,
right, top,
right, cy
)
cubicTo(
right, bottom,
right, bottom,
cx, bottom
)
cubicTo(
left, bottom,
left, bottom,
left, cy
)
}
canvas.drawPath(badgePath, badgePaint)
canvas.drawTextCentered(badgeText, cx, cy, badgeTextPaint, badge.drawRect)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment