我想繪製一個正方形,其功能如下。JavaScript畫布創建廣場
如何修改以下函數來創建正方形。
function square() {
var tool = this;
this.started = false;
this.mousedown = function (ev) {
context.beginPath();
context.moveTo(ev._x, ev._y);
tool.started = true;
};
this.mousemove = function (ev) {
if (tool.started && checkboxSquare.checked) {
context.lineTo(ev._x, ev._y);
context.stroke();
}
};
this.mouseup = function (ev) {
if (tool.started && checkboxSquare.checked) {
tool.mousemove(ev);
tool.started = false;
}
};
}
內建的rect()方法有什麼問題? – Feathercrown
@羽毛冠我的意思是用鼠標繪製一個方形/記錄我不知道如何修改以實現這個功能 – Micheasl
您是否希望將這個方形實際放置在畫布上mouseup? – Feathercrown