You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @DanielMartinus I did a quick canvas extension to draw a star, but the physic brokes when using it, I'm probably missing something there.
fun Canvas.drawStar(rectF: RectF, paint: Paint){
onDraw(this, paint, rectF)
}
private fun onDraw(canvas: Canvas, paint: Paint, rectF: RectF) {
val spikes = 5
var rot = Math.PI / 2 * 3
val step = Math.PI / spikes
val path = Path()
val midX = rectF.centerX()
val midy = rectF.centerY()
val outerRadius= if (midX > midy) midy else midX
val innerRadius = outerRadius / 2
paint.style = Paint.Style.FILL
path.moveTo(midX, midy - outerRadius)
(0..spikes).forEach{ _ ->
var x: Float = (midX + Math.cos(rot) * outerRadius).toFloat()
var y: Float = (midy + Math.sin(rot) * outerRadius).toFloat()
path.lineTo(x, y)
rot += step
x = (midX + Math.cos(rot) * innerRadius).toFloat()
y = (midy + Math.sin(rot) * innerRadius).toFloat()
path.lineTo(x, y)
rot += step
}
path.lineTo(midX, midy - outerRadius)
path.close()
canvas.drawPath(path, paint)
}
I think giving a documentation on how to properly make an extension without breaking the physic could help introduce new shape and let people do their own fork for the shapes they need.
Lots of stuff is missing, for example that you're able to create your own emitter. Also things can be explained in a better way.
The text was updated successfully, but these errors were encountered: