您可能要強制在繪製線的最小長度。要做到這一點,利用這一示例代碼的鉛筆部分,改變它的東西是這樣的:
tools.pencil = function() {
var tool = this;
// variables for last x, y and min_length of line
var lx;
var ly;
var min_length = 3;
this.started = false;
// This is called when you start holding down the mouse button.
// This starts the pencil drawing.
this.mousedown = function (ev) {
context.beginPath();
context.moveTo(ev._x, ev._y);
tool.started = true;
// update last x,y coordinates
lx = ev._x;
ly = ev._y;
};
// This function is called every time you move the mouse. Obviously, it only
// draws if the tool.started state is set to true (when you are holding down
// the mouse button).
this.mousemove = function (ev) {
if (tool.started && (Math.sqrt(Math.pow(lx - ev._x, 2) + Math.pow(ly - ev._y, 2)) > min_length)) {
context.lineTo(ev._x, ev._y);
context.stroke();
lx = ev._x;
ly = ev._y;
}
};
// This is called when you release the mouse button.
this.mouseup = function (ev) {
if (tool.started) {
tool.mousemove(ev);
tool.started = false;
img_update();
}
};
};
謝謝,這是非常令人印象深刻的 – 2017-04-05 07:48:10