Advertisement
Kostiggig

Untitled

Aug 14th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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(0.dp))
  21. .background(Color.Transparent)
  22. .border(1.dp, Color.Black)
  23. ) {
  24. val step = 10.dp // line width
  25. val angleDegrees = 35f // todo adjust depending on roundedCornerShape
  26. val stepPx = step.toPx()
  27. val stepsCount = (size.width / stepPx).roundToInt()
  28. val actualStep = size.width / stepsCount
  29. val dotSize = Size(width = actualStep, height = size.height * 2)
  30. for (i in start..stepsCount step 2) {
  31. val rect = Rect(
  32. offset = Offset(x = i * actualStep, y = (size.height - dotSize.height) / 2),
  33. size = dotSize,
  34. )
  35. rotate(angleDegrees, pivot = rect.center) {
  36. drawRect(
  37. gray,
  38. topLeft = rect.topLeft,
  39. size = rect.size,
  40. )
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement