Created
April 22, 2021 21:25
-
-
Save Oleur/b9954b6aa3e92d98ade0356d2476b7d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fun drawTicketPath(size: Size, cornerRadius: Float): Path { | |
return Path().apply { | |
reset() | |
// Top left arc | |
arcTo( | |
rect = Rect( | |
left = -cornerRadius, | |
top = -cornerRadius, | |
right = cornerRadius, | |
bottom = cornerRadius | |
), | |
startAngleDegrees = 90.0f, | |
sweepAngleDegrees = -90.0f, | |
forceMoveTo = false | |
) | |
lineTo(x = size.width - cornerRadius, y = 0f) | |
// Top right arc | |
arcTo( | |
rect = Rect( | |
left = size.width - cornerRadius, | |
top = -cornerRadius, | |
right = size.width + cornerRadius, | |
bottom = cornerRadius | |
), | |
startAngleDegrees = 180.0f, | |
sweepAngleDegrees = -90.0f, | |
forceMoveTo = false | |
) | |
lineTo(x = size.width, y = size.height - cornerRadius) | |
// Bottom right arc | |
arcTo( | |
rect = Rect( | |
left = size.width - cornerRadius, | |
top = size.height - cornerRadius, | |
right = size.width + cornerRadius, | |
bottom = size.height + cornerRadius | |
), | |
startAngleDegrees = 270.0f, | |
sweepAngleDegrees = -90.0f, | |
forceMoveTo = false | |
) | |
lineTo(x = cornerRadius, y = size.height) | |
// Bottom left arc | |
arcTo( | |
rect = Rect( | |
left = -cornerRadius, | |
top = size.height - cornerRadius, | |
right = cornerRadius, | |
bottom = size.height + cornerRadius | |
), | |
startAngleDegrees = 0.0f, | |
sweepAngleDegrees = -90.0f, | |
forceMoveTo = false | |
) | |
lineTo(x = 0f, y = cornerRadius) | |
close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment