<canvas width="600" height="400"> </canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
pincel.fillStyle = "grey";
pincel.fillRect(0,0,600,400);
function mostrarMensaje(evento){
var x = evento.pageX - pantalla.offsetLeft; //pos x
var y = evento.pageY - pantalla.offsetTop; //pos y
var d = new Date(); //crea una variable de tipo date
var hora = checkTime(d.getHours()) + ":" + checkTime(d.getMinutes()) + ":" + checkTime(d.getSeconds());
function checkTime(i){
if (i<10){
i="0" + i;
}
return i;
}
alert("La hora es: " + hora + " y las coordenadas son: x=" + x + ", y=" + y);
}
pantalla.onclick = mostrarMensaje;
</script>
<canvas width="600" height="400"></canvas>
<script>
var pantalla = document.querySelector("canvas");
var pincel = pantalla.getContext("2d");
pincel.fillStyle = "grey";
pincel.fillRect(0,0,600,400);
function exibirAlerta(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
console.log(evento);
alert(x+ "," + y);
}
function dibujarCirculo(evento){
var x = evento.pageX - pantalla.offsetLeft;
var y = evento.pageY - pantalla.offsetTop;
pincel.fillStyle = "blue";
pincel.beginPath();
pincel.arc(x,y,10,0,2*3.14);
pincel.fill();
console.log(x+ ","+ y);
}
pantalla.onclick = dibujarCirculo;
</script>