Loading...
Javascript

Rettangolo con dimensioni casuali

lezioni javascript ripetizioni esercizi

Disegnare un rettangolo con altezza H e base B generati casualmente. Di seguito il listato:

<html>
<body>
<canvas id=”myCanvas” width=”300″ height=”150″ style=”border:1px solid #d3d3d3;”></canvas>
<script>
var c = document.getElementById(“myCanvas”);
var ctx = c.getContext(“2d”);
ctx.beginPath();
ctx.moveTo(0, 0);
a=Math.random()*100;//base
h=Math.random()*100;//altezza
ctx.rect(0,0,a,h);
ctx.stroke();
</script>
</body>
</html>