<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid
#d3d3d3;" onclick="press()" onmousedown="mouse_position()">
</canvas>
<script>
function mouse_position(){
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
let e = window.event;
let posX = e.clientX;
let posY = e.clientY;
ctx.fillStyle = '#' + Math.floor(Math.random()*16777215).toString(16);
let size = Math.floor(Math.random()*50)+25;
ctx.fillRect(posX, posY, size, size);
}
</script>
</body>
</html>
|