var date = new Date;
var drawFlag = false;
var oldX = 0;
var oldY = 0;
window.addEventListener("load", function(){
var can = document.getElementById("myCanvas");
can.addEventListener("mousemove", draw, true);
can.addEventListener("mousedown", function(e){
drawFlag = true;
oldX = e.clientX;
oldY = e.clientY;
}, false);
can.addEventListener("mouseup", function(){
drawFlag = false;
}, false);
}, true);
// 描画処理
function draw(e){
if (!drawFlag) return;
var x = e.clientX;
var y = e.clientY;
var can = document.getElementById("myCanvas");
var context = can.getContext("2d");
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
context.strokeStyle = "rgba("+ [r,g,b].join(',') + ",255)";
context.lineWidth = 200;
context.beginPath();
context.moveTo(oldX, oldY);
context.lineTo(x, y);
context.stroke();
context.closePath();
context.strokeStyle = "rgba(255,0,0,255)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(oldX, oldY);
context.lineTo(x, y);
context.stroke();
context.closePath();
oldX = x;
oldY = y;
console.log(date.toLocaleString() + ' : ' + x + ',' + y);
}
dmFyIGRhdGUgPSBuZXcgRGF0ZTsKdmFyIGRyYXdGbGFnID0gZmFsc2U7CnZhciBvbGRYID0gMDsKdmFyIG9sZFkgPSAwOwp3aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcigibG9hZCIsIGZ1bmN0aW9uKCl7Cgl2YXIgY2FuID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm15Q2FudmFzIik7CgljYW4uYWRkRXZlbnRMaXN0ZW5lcigibW91c2Vtb3ZlIiwgZHJhdywgdHJ1ZSk7CgljYW4uYWRkRXZlbnRMaXN0ZW5lcigibW91c2Vkb3duIiwgZnVuY3Rpb24oZSl7CgkJZHJhd0ZsYWcgPSB0cnVlOwoJCW9sZFggPSBlLmNsaWVudFg7CgkJb2xkWSA9IGUuY2xpZW50WTsKCX0sIGZhbHNlKTsKCWNhbi5hZGRFdmVudExpc3RlbmVyKCJtb3VzZXVwIiwgZnVuY3Rpb24oKX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