Last active
September 29, 2022 11:56
-
-
Save nikhil-mandlik-dev/b4ef5690d13f22e7a9535a7e2d87e750 to your computer and use it in GitHub Desktop.
Drawing Infinity Path
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
Canvas( | |
modifier = Modifier | |
.fillMaxWidth(fraction = 0.8f) | |
.fillMaxHeight(fraction = 0.5f) | |
) { | |
// Start & End Points | |
val start = Offset(0f, size.height / 2) | |
val end = Offset(size.width, size.height / 2) | |
// Control Points | |
val c1 = Offset(size.width / 4, 0f) | |
val c2 = Offset(3 * size.width / 4, size.height) | |
val c3 = Offset(3 * size.width / 4, 0f) | |
val c4 = Offset(size.width / 4, size.height) | |
val infinityPath = Path().apply { | |
// Move to Start Position | |
moveTo(start.x, start.y) | |
// first curve : start -> c1 -> c2 -> end | |
cubicTo( | |
c1.x, c1.y, | |
c2.x, c2.y, | |
end.x, end.y | |
) | |
// Second curve : end -> c3 -> c4 -> start | |
cubicTo( | |
c3.x, c3.y, | |
c4.x, c4.y, | |
start.x, start.y | |
) | |
// Close the Path | |
close() | |
} | |
drawPath( | |
path = infinityPath, | |
color = Color.Black, | |
style = Stroke(width = 1.dp.toPx()), | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment