Reputation: 14022
How we can draw 2D curves like this in Canvas
?
All similar curves have mathematical formula
or are fractals
, but the canvas only has some methods for drawing simple shapes like a triangle or rectangle. I know that most curves can divide into simpler shapes such as with drawing a Heart Curve, but is there an easier way to draw 2D curves with the canvas?
Upvotes: 1
Views: 5626
Reputation: 12121
If you look up how to draw 2D curves in general you'll either be drawing points or lines and it only looks smooth.
Your question has two parametric forms and one fractal form. All can be drawn with lines and points. The parametric forms can be done directly via the algorithms in your question or could be transformed into more general ones like the Bezier curve as mentioned by @leenephi
Most of the time the equations/algorithms for generating fractals are using lines, Koch Snowflake, or points, the Mandelbrot set. If you actually understand how to generate them, you'll see that fractals are less about drawing 'a curve' and more about process (recursion) and results (self-similarity).
Upvotes: 1
Reputation: 900
Using the Path object you can do some fancier lines and curves in the Canvas. Just randomly found these two questions concerning those; I hope they can point you in the right direction as I personally have not used them.
Draw a perfect curve connecting three points
Upvotes: 3
Reputation: 43728
You have to approximate the curve by simpler primitives for example short line segments.
Upvotes: 0