Skip to content

Instantly share code, notes, and snippets.

@am3n
Last active October 1, 2020 09:51
Show Gist options
  • Save am3n/60d466d1267ed4f008b235841077aa57 to your computer and use it in GitHub Desktop.
Save am3n/60d466d1267ed4f008b235841077aa57 to your computer and use it in GitHub Desktop.
val width = getScreenWidth()
val height = getScreenHeight()
val min = min(width, height)
val radius = min/2 * 4/5
val center = PointF(0f, 0f)
val points = Array(5) { PointF() }
val angle36 = toRadians(36.0)
val angle72 = toRadians(72.0)
points[0].x = center.x + (sin(angle36)*radius).toFloat()
points[0].y = center.y + (cos(angle36)*radius).toFloat()
points[4].x = center.x - (sin(angle36)*radius).toFloat()
points[4].y = points[0].y
points[2].x = center.x
points[2].y = center.y - radius.toFloat()
points[1].x = center.x + (sin(angle72)*radius).toFloat()
points[1].y = center.y - (cos(angle72)*radius).toFloat()
points[3].x = center.x - (sin(angle72)*radius).toFloat()
points[3].y = points[1].y
var i = 0
val imgs = Array(5) { AppCompatImageView(this) }
imgs.forEach { actTest.addView(it) }
imgs[i].setImageResource(R.drawable.ic_circle)
imgs[i].x = points[i].x
imgs[i].y = points[i].y
i++
imgs[i].setImageResource(R.drawable.ic_circle)
imgs[i].x = points[i].x
imgs[i].y = points[i].y
i++
imgs[i].setImageResource(R.drawable.ic_circle)
imgs[i].x = points[i].x
imgs[i].y = points[i].y
i++
imgs[i].setImageResource(R.drawable.ic_circle)
imgs[i].x = points[i].x
imgs[i].y = points[i].y
i++
imgs[i].setImageResource(R.drawable.ic_circle)
imgs[i].x = points[i].x
imgs[i].y = points[i].y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment