lundi 29 février 2016

Randomly sized rectangles on JavaScript canvas

I'm trying to draw randomly sized rectangles on my canvas. This is the code I have but it doesn't show anything when I run it.

 // JavaScript Document
window.addEventListener('load', drawLine);

function drawLine() {
    var canvas = document.getElementById('myCanvas');
    var context = canvas.getContext('2d'); 
    {
        context.beginPath();
        context.lineWidth = "100";
        context.strokeStyle = 'black';
        context.rect(910, 400, Math.floor((Math.random() * 150) + 150), Math.floor((Math.random() * 150) + 150));
        context.stroke();
        context.closePath();
    }
}




Aucun commentaire:

Enregistrer un commentaire