mercredi 8 novembre 2017

Urbem aut Silvam


<center>
<svg id="svgPaysage" xmlns="http://www.w3.org/2000/svg" width="400" height="300">
<defs>
  <pattern id="Pattern" x="0" y="0" width="0.125" height="0.05">
    <rect x="0" y="0" width="5" height="5" stroke="black" fill="none"/>
  </pattern>
</defs>
</svg>
<br>
<button onclick="myFunctionP()">Generate</button>
</center>

<script>

function myFunctionP() {
var svgns = "http://www.w3.org/2000/svg";

var d = Math.floor(180*Math.random());
var rs = Math.floor(80*Math.random()+20);

var rect0 = document.createElementNS(svgPaysage.namespaceURI, 'rect');
    rect0.setAttributeNS(null, 'x', 0);
    rect0.setAttributeNS(null, 'y', 0);
    rect0.setAttributeNS(null, 'width', 400);
    rect0.setAttributeNS(null, 'height', 300);
    rect0.setAttributeNS(null, 'fill', '#'+Math.round(0xFFFFFF * Math.random()).toString(16));

var rect1 = document.createElementNS(svgPaysage.namespaceURI, 'rect');
    rect1.setAttributeNS(null, 'x', 0);
    rect1.setAttributeNS(null, 'y', 200);
    rect1.setAttributeNS(null, 'width', 400);
    rect1.setAttributeNS(null, 'height', 100);
    rect1.setAttributeNS(null, 'fill', '#'+Math.round(0xFFFFFF * Math.random()).toString(16));

var circle0 = document.createElementNS(svgPaysage.namespaceURI, 'circle');
    circle0.setAttributeNS(null, 'cx', 50);
    circle0.setAttributeNS(null, 'cy', 200);
    circle0.setAttributeNS(null, 'r', rs);
    circle0.setAttributeNS(null, 'fill', '#'+Math.round(0xFFFFFF * Math.random()).toString(16));
    circle0.setAttributeNS(null, 'transform', 'rotate('+d+' 200 200)');

var g0 = document.createElementNS(svgPaysage.namespaceURI, 'g');

svgPaysage.appendChild(rect0);
svgPaysage.appendChild(circle0);
svgPaysage.appendChild(rect1);
svgPaysage.appendChild(g0);

var na = Math.floor(24*Math.random()+1);
var colim = '#'+Math.round(0xFFFFFF * Math.random()).toString(16);

for (var i = 0; i < na; i++) {

var a = Math.floor(390*Math.random());
var b = Math.floor(80*Math.random()+10);
var c = 100+(100-b)

var rect2 = document.createElementNS(svgPaysage.namespaceURI, 'rect');
    rect2.setAttributeNS(null, 'x', a);
    rect2.setAttributeNS(null, 'y', c);
    rect2.setAttributeNS(null, 'width', 20);
    rect2.setAttributeNS(null, 'height',b);
    rect2.setAttributeNS(null, 'fill', colim);

var rect3 = document.createElementNS(svgPaysage.namespaceURI, 'rect');
    rect3.setAttributeNS(null, 'x', a);
    rect3.setAttributeNS(null, 'y', c);
    rect3.setAttributeNS(null, 'width', 20);
    rect3.setAttributeNS(null, 'height',b);
    rect3.setAttributeNS(null, 'fill', 'url(#Pattern)');

svgPaysage.appendChild(rect2);
svgPaysage.appendChild(rect3);
}

var ni = Math.floor(24*Math.random()+1);

var randomString0 = new Array ();
    randomString0[0] = "http://217.199.187.63/shepwaytreesurgery.com/wp-content/uploads/2014/07/tree.png";
    randomString0[1] = "http://www.wilsoninfo.com/trees/maple-tree-1.png";
    randomString0[2] = "http://images.vectorhq.com/images/thumbs/000/tree-psd-428032.png";
    randomString0[3] = "http://www.immediateentourage.com/ie/wp-content/uploads/2013/08/Cropped-Tree-144x144.png";
    randomString0[4] = "http://images.vectorhq.com/images/thumbs/17d/tree-psd-412259.png";
    randomString0[5] = "https://emojipedia-us.s3.amazonaws.com/thumbs/120/emoji-one/104/palm-tree_1f334.png";
    randomString0[6] = "https://emojipedia-us.s3.amazonaws.com/thumbs/120/apple/96/palm-tree_1f334.png";
    randomString0[7] = "http://www.pngall.com/wp-content/uploads/2016/04/Palm-Tree-PNG-180x180.png";
    randomString0[8] = "http://www.pngall.com/wp-content/uploads/2016/03/Tree-PNG-Clipart-180x180.png";
    randomString0[9] = "https://cdn.pixabay.com/photo/2016/09/10/10/14/tree-1658814__180.png";
    randomString0[10] = "https://cdn.pixabay.com/photo/2016/03/31/18/06/tree-1294129__180.png";
    randomString0[11] = "http://d3bzucwb8zrw42.cloudfront.net/wp-content/uploads/2013/12/tree.png";
    randomString0[12] = "https://cdn.pixabay.com/photo/2016/07/12/08/19/tree-1511608__180.png";
    randomString0[13] = "http://t09.deviantart.net/gWbp_RpXqL_VVDI3nCNoO5St3ww=/fit-in/150x150/filters:no_upscale():origin()/pre04/0b85/th/pre/i/2013/136/e/a/tree_3__png_with_transparency__by_bupaje-d65gvf3.png";
    randomString0[14] = "http://t13.deviantart.net/NZu8dEK3zVdBJ5OKgcgpM20uTwo=/fit-in/150x150/filters:no_upscale():origin()/pre05/b7fc/th/pre/i/2010/258/6/7/tree_15_a_png_by_gd08-d2ysdnz.png";
    randomString0[15] = "https://www.spreadshirt.com/image-server/v1/designs/1001895441,width=178,height=178/color-tree.png";
    var va = Math.floor(16*Math.random());

var randomString1 = new Array ();
    randomString1[0] = "https://media.giphy.com/media/YoQkSZ8T4yDHG/giphy.gif";
    randomString1[1] = "http://www.pixeljoint.com/files/icons/finished__r153083551_8401.gif";
    randomString1[2] = "http://www.gifandgif.eu/animated_gif/Birds/Animated%20Gif%20Birds%20(22).gif";
    randomString1[3] = "http://www.animatedimages.org/data/media/591/animated-parrot-image-0006.gif";
    randomString1[4] = "http://www.mythicalrealm.com/images/phoenixani.gif";
    randomString1[5] = "http://orig04.deviantart.net/6e8c/f/2014/040/c/e/flappy_bird_by_funcatty-d75spu0.gif";
    randomString1[6] = "http://www.nhlcyberfamily.org/special/bird002.gif";
    randomString1[7] = "http://www.mtephraimschools.org/RWK/News/Images/flying%20witch,%20animated.gif";
    var vo = Math.floor(8*Math.random());


for (var i = 0; i < ni; i++) {

var a = Math.floor(390*Math.random());
var b = Math.floor(25*Math.random()+10);
var c = 103+(100-b)

var image0 = document.createElementNS(svgPaysage.namespaceURI, 'image');
    image0.setAttributeNS(null, 'x', a);
    image0.setAttributeNS(null, 'y', c);
    image0.setAttributeNS(null, 'width', b);
    image0.setAttributeNS(null, 'height', b);
    image0.setAttributeNS('http://www.w3.org/1999/xlink', 'href', randomString0[va]);

svgPaysage.appendChild(image0);

}

var no = Math.floor(9*Math.random()+1);

var animation0 = document.createElementNS(svgns, 'animateMotion');
    animation0.setAttribute('values', '-400 0;400 0');
    animation0.setAttribute('begin', '0s');
    animation0.setAttribute('dur', '6s');
    animation0.setAttribute('repeatCount', 'indefinite');

for (var i = 0; i < no; i++) {

var xo = Math.floor(400*Math.random());
var yo = Math.floor(100*Math.random());
var to = Math.floor(20*Math.random()+10);

var image1 = document.createElementNS(svgPaysage.namespaceURI, 'image');
    image1.setAttributeNS(null, 'x', xo);
    image1.setAttributeNS(null, 'y', yo);
    image1.setAttributeNS(null, 'width', to);
    image1.setAttributeNS(null, 'height', to);
    image1.setAttributeNS('http://www.w3.org/1999/xlink', 'href', randomString1[vo]);

g0.appendChild(image1);

}


g0.appendChild(animation0);

var lieu;
    if (ni < na) {
        lieu = "VILLE";
    } else {
        lieu = "FORET";
    }

var text0 = document.createElementNS(svgPaysage.namespaceURI, 'text');
    text0.setAttributeNS(null, 'x', '200');
    text0.setAttributeNS(null, 'y', '280');
    text0.setAttributeNS(null, 'fill', '#000');
    text0.setAttributeNS(null, 'font-family', 'Verdana');
    text0.setAttributeNS(null, 'text-anchor', 'middle');
    text0.textContent = lieu;

svgPaysage.appendChild(text0);


}


var lieu;
    if (ni < na) {
        lieu = "VILLE";
    } else {
        lieu = "FORET";
    }




</script>