Skip to content

Instantly share code, notes, and snippets.

@nikhil-mandlik-dev
Last active September 29, 2022 11:56
Show Gist options
  • Save nikhil-mandlik-dev/b4ef5690d13f22e7a9535a7e2d87e750 to your computer and use it in GitHub Desktop.
Save nikhil-mandlik-dev/b4ef5690d13f22e7a9535a7e2d87e750 to your computer and use it in GitHub Desktop.
Drawing Infinity Path
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