Examle of 50 curve SVG
HTML
<button id="gobutton">GO!</button>
<svg id="SVGview" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="350" height="250">
<g id="maingroup">
</g>
</svg>
JavaScript
var points = [];
var output = [];
var canvas = document.querySelector('canvas');
function pointsToSVG() {
var svgNS = "http://www.w3.org/2000/svg";
var svg = document.getElementById("SVGview");
var maingroup = document.getElementById("maingroup");
while (maingroup.firstChild) {
maingroup.removeChild(maingroup.firstChild);
} //clear old svg data.
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
group = document.createElementNS(svgNS, "g");
group.setAttributeNS(null, "stroke", color);
group.setAttributeNS(null, "fill", "none");
var path = 'M';
path += ' ' + points[0] + ',' + points[1];
path += 'Q'
path += ' ' + points[2] + ',' + points[3];
path += ' ' + points[4] + ',' + points[5];
path += 'T'
for (var m = 6; m < points.length; m += 2) {
path += ' ' + points[m] + ',' + points[m + 1];
}
var d = document.createElementNS(svgNS, "path");
d.setAttributeNS(null, "d", path);
group.appendChild(d);
maingroup.appendChild(group);
}
var gobutton = document.getElementById('gobutton');
gobutton.addEventListener('click', function() {
points = [];
for (var i = 0; i < 50; i++) {
points.push( 100 + Math.random() * 50);
points.push( 100 + Math.random() * 50);
}
pointsToSVG();
});