nickfrancis.me nickfrancis.me - 1 month ago 25
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.
Thanks

Answer

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: http://www.mathematische-basteleien.de/heart.htm

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: http://code.google.com/p/android-page-curl/

Hope this helps!