implement currentTool
This commit is contained in:
parent
773dab7b75
commit
b811c80009
1 changed files with 5 additions and 3 deletions
|
@ -155,6 +155,8 @@
|
||||||
eraser.data[i+3] = 0;
|
eraser.data[i+3] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentTool = pen;
|
||||||
|
|
||||||
var drawing = false;
|
var drawing = false;
|
||||||
canvas.onmousedown = function() { drawing = true; }
|
canvas.onmousedown = function() { drawing = true; }
|
||||||
document.onmouseup = function() {
|
document.onmouseup = function() {
|
||||||
|
@ -183,15 +185,15 @@
|
||||||
var posX = e.offsetX * canvas.width / canvas.offsetWidth - 1;
|
var posX = e.offsetX * canvas.width / canvas.offsetWidth - 1;
|
||||||
var posY = e.offsetY * canvas.height / canvas.offsetHeight - 1;
|
var posY = e.offsetY * canvas.height / canvas.offsetHeight - 1;
|
||||||
|
|
||||||
ctx.putImageData(pen, posX, posY);
|
ctx.putImageData(currentTool, posX, posY);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPen() {
|
function setPen() {
|
||||||
alert("pen");
|
currentTool = pen;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEraser() {
|
function setEraser() {
|
||||||
alert("eras");
|
currentTool = eraser;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearCanvas() {
|
function clearCanvas() {
|
||||||
|
|
Reference in a new issue