DanielMartinus / Konfetti

Celebrate more with this lightweight confetti particle system 🎊
ISC License
3.16k stars 299 forks source link

Create wiki with better documentation #28

Open DanielMartinus opened 7 years ago

DanielMartinus commented 7 years ago

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.

soundlicious commented 5 years ago

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.