I’m trying to draw a line that starts as a thin line and then gadually widens until the end. I need to draw semi-smooth curves (composite out of several straight lines) and I’m having problems finding a way to solve this task.
This fiddle shows my problem:
When you call stroke(), the currently set lineWidth is used to stroke the entire line. My first thought was to draw each line piece individually, but of course, this leaves noticeable gaps in the line at the corners.
What is my best option here? Should I resort to drawing polygons (trapezoids) to get the corners right?
Is there an easier way?
(Edit: Note that I am not trying to actually draw ellipses or any other basic shapes; I’m trying to plot mathematical functions, using line thickness to represent velocity)
For those interested, I have come up with two solutions to my problem.
The first idea was to actually draw each point as a corner, using canvas to draw a neat angle. A demo can be seen at:
http://jsfiddle.net/7BkyK/2/
The second and much prettier solution, as suggested by Shmiddty, is to use bezier curves. This proved to be a great solution:
http://jsfiddle.net/Ssrv9/1/