<code> window.H5lock =
function
(obj){
this.height = obj.height;
this.width = obj.width;
this.chooseType = Number(window.localStorage.getItem(
'chooseType'
)) || obj.chooseType;
};
function
getDis(a, b) {
return
Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
};
H5lock.prototype.pickPoints =
function
(fromPt, toPt) {
var
lineLength = getDis(fromPt, toPt);
var
dir = toPt.index > fromPt.index ? 1 : -1;
var
len = this.restPoint.length;
var
i = dir === 1 ? 0 : (len - 1);
var
limit = dir === 1 ? len : -1;
while
(i !== limit) {
var
pt = this.restPoint[i];
if
(getDis(pt, fromPt) + getDis(pt, toPt) === lineLength) {
this.drawPoint(pt.x, pt.y);
this.lastPoint.push(pt);
this.restPoint.splice(i, 1);
if
(limit > 0) {
i--;
limit--;
}
}
i+=dir;
}
}
H5lock.prototype.drawCle =
function
(x, y) {
this.ctx.strokeStyle =
'#CFE6FF'
;
this.ctx.lineWidth = 2;
this.ctx.beginPath();
this.ctx.arc(x, y, this.r, 0, Math.PI * 2, true);
this.ctx.closePath();
this.ctx.stroke();
}
H5lock.prototype.drawPoint =
function
() {
for
(
var
i = 0 ; i < this.lastPoint.length ; i++) {
this.ctx.fillStyle =
'#CFE6FF'
;
this.ctx.beginPath();
this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r / 2, 0, Math.PI * 2, true);
this.ctx.closePath();
this.ctx.fill();
}
}
</code>