Skip to content

Instantly share code, notes, and snippets.

@AndreVero
Last active February 24, 2024 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreVero/f4b3bdb518d8797cd708a500492f599b to your computer and use it in GitHub Desktop.
Save AndreVero/f4b3bdb518d8797cd708a500492f599b to your computer and use it in GitHub Desktop.
Draw secondary items in glovolike animation
// Draw secondary items
items.forEachIndexed { i, item ->
// Firstly count the angle on which we
// should position secondary item in degrees
// -90 will help to position degrees in
// the right appropriately (you can play around with that)
val angleInDegrees = (i * distance - 90)
// Convert angle to radians
val angleInRad = angleInDegrees * (PI / 180).toFloat()
// In essence, this function helps
// find the coordinates of a point on a circle based
// on its radius (mainCircleRadius),
// center (circleCenter), and the angle (angleInRad)
// at which you want to find the point.
val currentOffset = Offset(
x = mainCircleRadius.toPx() * cos(angleInRad) + circleCenter.x,
y = mainCircleRadius.toPx() * sin(angleInRad) + circleCenter.y
)
drawCircle(
color = Color.White,
radius = innerCircleRadius.toPx(),
center = currentOffset
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment