dimanche 10 mai 2015

how can use a loop to draw it multiple times in random places in my canvas?

I've drawn a leaf in canvas, but now i want to draw it multiple times on my canvas and in random places. I've mostly used bezier curves to draw my leaf, is and i do not know how to use a loop to create more of them in random places, because of the coordinates.

My code:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="800" height="800" style="border:1px solid #c3c3c3;">

</canvas>

<script>
var c = document.getElementById("myCanvas");
var context = c.getContext("2d");

       context.lineWidth = 5;


      context.beginPath();
      context.moveTo(100, 150);

      context.strokeStyle="#009900";
      context.bezierCurveTo(170, 110, 400, 10, 500, 150);
      context.stroke();



      context.moveTo(100, 150);
      context.strokeStyle="#009900";
      context.bezierCurveTo(170, 130, 430, 310, 500, 150);
      context.stroke();
      context.fillStyle = '#99FF66';
      context.fill();


      context.strokeStyle="#009900";
      context.moveTo(250, 150);
      context.bezierCurveTo(400, 100, 400, 180, 500, 150);
      context.stroke();
       context.closePath();


      context.beginPath();
      context.strokeStyle="#996633";
      context.moveTo(500, 150);
      context.lineTo(580,150);
      context.stroke();
      context.closePath();





</script>

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire