4 hour of search for wave in html, svg or canvas but didn't find anything what would look like in a picture.
How can I create wave like this? with smooth ending and filled with color ?
4 hour of search for wave in html, svg or canvas but didn't find anything what would look like in a picture.
How can I create wave like this? with smooth ending and filled with color ?
This shape can be achieved using bezierCurveTo()
in canvas. I'm sure the shape is possible in SVG as well, but I'm not as familiar with it, so below is a canvas demonstration.
The snippet is borrowed and adapted from the MDN article. Basically, you want a bezier curve that keeps the control points on the same y-axis as the start and end points. Make the curve more or less dramatic by moving the control points along the x-axis. The farther the first control point and second control point are to the start and end points (respectively) the more dramatic the curve will be.
I would start by building the graph in canvas using straight lines and adapting them to be bezier curves after the fact.
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var hw = 10, ho = hw / 2;
var x1 = 50, y1 = 20,
x2 = 230, y2 = 100,
cp1x = 120, cp1y = 20,
cp2x = 160, cp2y = 100;
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x2, y2);
ctx.stroke();
ctx.fillStyle = 'blue';
// start point
ctx.fillRect(x1 - ho, y1 - ho, hw, hw);
// end point
ctx.fillRect(x2 - ho, y2 - ho, hw, hw);
ctx.fillStyle = 'red';
// control point one
ctx.fillRect(cp1x - ho, cp1y - ho, hw, hw);
// control point two
ctx.fillRect(cp2x - ho, cp2y - ho, hw, hw);
<canvas id="canvas"></canvas>