jeudi 5 avril 2018

svg courbes



<svg width="400" height="400" id="svgCurbs" onclick="fcurbs()">
<rect width="400" height="400" fill="#24445C
" x="0" y="0"/>
</svg>
<script>
function fcurbs() {
for (var i = 0; i < 1; i++) {
var x1 = Math.floor(200*Math.random());
var x2 = Math.floor(200*Math.random())+200;
var y1 = Math.floor(400*Math.random());
var y2 = Math.floor(400*Math.random());
var a1 = Math.floor(360*Math.random());
var a2 = 360+a1;
var s1 = Math.floor(6*Math.random())+2;
var d1 = Math.floor(14*Math.random())+6;

var randomString0 = new Array ();
    randomString0[0] = "#9B95FF";
    randomString0[1] = "#FFC988";
    randomString0[2] = "#E880AC"; 
    randomString0[3] = "#7CE8D5";
    randomString0[4] = "#CEFF88";
    var color = Math.floor(5*Math.random());


var g1 = document.createElementNS(svgCurbs.namespaceURI, 'g');

var path1 = document.createElementNS(svgCurbs.namespaceURI, 'path');
    path1.setAttribute('d', 'm'+x1+','+y1+'C'+x1+','+y1+' 0,200 200,200C400,200 '+x2+','+y2+' '+x2+','+y2+'');
    path1.setAttribute('fill', 'none');
    path1.setAttribute('stroke', randomString0[color]);
    path1.setAttribute('stroke-width', s1);
    path1.setAttribute('stroke-dasharray', '0.5,20');
    path1.setAttribute('stroke-linecap', 'round');
    path1.setAttribute('opacity', '0.8');

var anim1 = document.createElementNS(svgCurbs.namespaceURI, 'animate');
    anim1.setAttribute('attributeName', 'stroke-dashoffset');
    anim1.setAttribute('begin', '0s');
    anim1.setAttribute('repeatCount', 'indefinite');
    anim1.setAttribute('dur', '1s');
    anim1.setAttribute('values', '0;40');

var anim2 = document.createElementNS(svgCurbs.namespaceURI, 'animateTransform');
    anim2.setAttribute('attributeName', 'transform');
    anim2.setAttribute('attributeType', 'xml');
    anim2.setAttribute('type', 'rotate');
    anim2.setAttribute('repeatCount', 'indefinite');
    anim2.setAttribute('dur', d1);
    anim2.setAttribute('values', ''+a1+' 200 200 ;'+a2+' 200 200');

    g1.appendChild(path1);
    g1.appendChild(anim1);
    g1.appendChild(anim2);
    svgCurbs.appendChild(g1);
}}

fcurbs()
</script>