-
-
Save KatieBarnett/be12ae9d65107d6e888241ce3ab6882d to your computer and use it in GitHub Desktop.
Heart 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
@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