Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created March 17, 2024 04:25
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 KatieBarnett/be12ae9d65107d6e888241ce3ab6882d to your computer and use it in GitHub Desktop.
Save KatieBarnett/be12ae9d65107d6e888241ce3ab6882d to your computer and use it in GitHub Desktop.
Heart path
@Composable
fun HeartLine(color: Color, modifier: Modifier = Modifier) {
val shapeRadius = LINE_WIDTH / 2
val dotSpacing = shapeRadius * 4
val density = LocalDensity.current
val heartPath = remember {
with(density) {
Path().apply {
val width = (shapeRadius * 2).toPx()
val height = (shapeRadius * 2).toPx()
moveTo(width / 2, height / 4)
cubicTo(width / 4, 0f, 0f, height / 3, width / 4, height / 2)
lineTo(width / 2, height * 3 / 4)
lineTo(width * 3 / 4, height / 2)
cubicTo(width, height / 3, width * 3 / 4, 0f, width / 2, height / 4)
}
}
}
Canvas(modifier) {
val pathEffect = PathEffect.stampedPathEffect(
shape = heartPath,
advance = dotSpacing.toPx(),
phase = 0f,
style = StampedPathEffectStyle.Translate
)
drawLine(
color = color,
start = Offset(0f, 0f),
end = Offset(size.width, 0f),
pathEffect = pathEffect,
strokeWidth = shapeRadius.toPx()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment