Advertisement
Kostiggig

Untitled

Aug 14th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. val scope = rememberCoroutineScope()
  2. val red = Color(0xFFFF7F4D)
  3. val gray = Color(0xFF34343C).copy(alpha = 0.12f)
  4. var start by remember {
  5. mutableStateOf(-1)
  6. }
  7. LaunchedEffect(key1 = Unit) {
  8. while (scope.isActive) {
  9. delay(150)
  10. start = if (start == -1) 0 else -1
  11. }
  12. }
  13. Canvas(
  14. Modifier
  15. .padding(top = 100.dp)
  16. .border(1.dp, Color.Black)
  17. .padding(10.dp)
  18. .fillMaxWidth()
  19. .height(40.dp)
  20. .clip(RoundedCornerShape(12.dp))
  21. .background(red)
  22. ) {
  23. val step = 10.dp // line width
  24. val angleDegrees = 35f // todo adjust depending on roundedCornerShape
  25. val stepPx = step.toPx()
  26. val stepsCount = (size.width / stepPx).roundToInt()
  27. val actualStep = size.width / stepsCount
  28. val dotSize = Size(width = actualStep, height = size.height * 2)
  29. for (i in start..stepsCount step 2) {
  30. val rect = Rect(
  31. offset = Offset(x = i * actualStep, y = (size.height - dotSize.height) / 2),
  32. size = dotSize,
  33. )
  34. rotate(angleDegrees, pivot = rect.center) {
  35. drawRect(
  36. gray,
  37. topLeft = rect.topLeft,
  38. size = rect.size,
  39. )
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement