- 8 months ago 127
Android Question

android how to draw triangle, star, square , heart on the canvas

I am able to draw circle and rectangle on canvas by using path.addCircle() and path.addRect().Like that i want on touch i am able to draw triangle, star, square and heart.
How can I do that?
Give me a way with sample examples.


You have to find out the math behind that figures. The triangle and the start are quite easy but here is how you can draw a heart:

To draw special paths you should create them adding points, ellipses etc, the canvas supports clipping mask of a specified path and so you can set the clipping mask of a heart push the pasth to the matrix, draw the content of the heart and ten pop it again.

That's what I'm doing to achieve a simulated 2D page curl effect on andriod:

Hope this helps!