Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val scope = rememberCoroutineScope()
- val red = Color(0xFFFF7F4D)
- val gray = Color(0xFF34343C).copy(alpha = 0.12f)
- var start by remember {
- mutableStateOf(-1)
- }
- LaunchedEffect(key1 = Unit) {
- while (scope.isActive) {
- delay(150)
- start = if (start == -1) 0 else -1
- }
- }
- Canvas(
- Modifier
- .padding(top = 100.dp)
- .border(1.dp, Color.Black)
- .padding(10.dp)
- .fillMaxWidth()
- .height(40.dp)
- .clip(RoundedCornerShape(12.dp))
- .background(red)
- ) {
- val step = 10.dp // line width
- val angleDegrees = 35f // todo adjust depending on roundedCornerShape
- val stepPx = step.toPx()
- val stepsCount = (size.width / stepPx).roundToInt()
- val actualStep = size.width / stepsCount
- val dotSize = Size(width = actualStep, height = size.height * 2)
- for (i in start..stepsCount step 2) {
- val rect = Rect(
- offset = Offset(x = i * actualStep, y = (size.height - dotSize.height) / 2),
- size = dotSize,
- )
- rotate(angleDegrees, pivot = rect.center) {
- drawRect(
- gray,
- topLeft = rect.topLeft,
- size = rect.size,
- )
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement