canvas

by egoregor

HTML

<canvas id="canvas" width=250 height=250>canvas</canvas>
<button value="OK" onclick="can()">OK</button>

CSS

body {text-align:center;}
#canvas {
    margin:30px auto;
    border:1px solid black;
}

JavaScript

var x = Math.floor(Math.random() * (100 + 1));
var y = Math.floor(Math.random() * (100 + 1));
//canvas = document.getElementById("canvas").getContext("2d");
//function  paint() {canvas.fillRect(100, 100, x, y);}
//paint();

var brush = new Object();
brush.x = Math.floor(Math.random() * (100 + 1));
brush.y = Math.floor(Math.random() * (100 + 1));
brush.paint = function() {
    canvas.fillRect(100, 100, this.x, this.y);
}
    function can() {
        canvas = document.getElementById("canvas").getContext("2d");
        canvas.fillRect(100, 100, 50, 50);
    }