Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created September 17, 2021 20:03
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 Ahmed-Sellami/c6f0e907635e7934914e11e93db0c531 to your computer and use it in GitHub Desktop.
Save Ahmed-Sellami/c6f0e907635e7934914e11e93db0c531 to your computer and use it in GitHub Desktop.
val explosionParticleRadius: Float
val explosionRadius: Float
with(LocalDensity.current) {
explosionParticleRadius = dimensionResource(id = R.dimen.explosion_particle_radius).toPx()
explosionRadius = dimensionResource(id = R.dimen.explosion_radius).toPx()
}
Box {
Canvas(/* ... */) {/* ... */}
Canvas(modifier = Modifier.height(itemHeightDp) {
val numberOfExplosionParticles = 10
val particleAngle = Math.PI * 2 / numberOfExplosionParticles
var angle = 0.0
repeat(numberOfExplosionParticles / 2 + 1) {
val hTranslation = (cos(angle).toFloat() * explosionRadius)
val vTranslation = (sin(angle).toFloat() * explosionRadius)
translate(hTranslation, vTranslation) {
drawCircle(
color = shoesArticle.color,
radius = explosionParticleRadius
)
}
if (vTranslation.round(2) != -vTranslation.round(2)) {
translate(hTranslation, -vTranslation) {
drawCircle(
color = shoesArticle.color,
radius = explosionParticleRadius
)
}
}
angle += particleAngle
}
}
Box(/* ... */) {/* ... */}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment