-
-
Save KatieBarnett/acf87bc8382526228aa556a1097b8380 to your computer and use it in GitHub Desktop.
Triangle Zig Zag
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 ZigZagLine(color: Color, modifier: Modifier = Modifier) { | |
val shapeWidth = LINE_WIDTH | |
val density = LocalDensity.current | |
val zigZagPath = remember { | |
with(density) { | |
Path().apply { | |
val zigZagWidth = shapeWidth.toPx() | |
val zigZagHeight = shapeWidth.toPx() | |
moveTo(0f, 0f) | |
lineTo(zigZagWidth / 2, zigZagHeight) | |
lineTo(zigZagWidth, 0f) | |
} | |
} | |
} | |
Canvas(modifier) { | |
val pathEffect = PathEffect.stampedPathEffect( | |
shape = zigZagPath, | |
advance = shapeWidth.toPx(), | |
phase = 0f, | |
style = StampedPathEffectStyle.Translate | |
) | |
drawLine( | |
color = color, | |
start = Offset(0f, 0f), | |
end = Offset(size.width, 0f), | |
pathEffect = pathEffect, | |
strokeWidth = shapeWidth.toPx() | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment