jQuery实现手势解锁密码特效

2020-05-23 06:23:15易采站长站整理

this.sList=[];
this.tP=new Point(0,0);

this.$element.append('<canvas class="main-c" width="'+options.width+'" height="'+options.height+'" >');
//this.$element.append('<canvas class="main-p" width="'+options.width+'" height="'+options.height+'" >');
this.$c= $(this.id+" .main-c")[0];
this.$ctx=this.$c.getContext('2d');

this.initDraw=function(){
this.$ctx.strokeStyle=this.color;
this.$ctx.lineWidth=2;
for(var j=0; j<3;j++ ){
for(var i =0;i<3;i++){
this.$ctx.moveTo(this.o/2+this.rr*2+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr));
this.$ctx.arc(this.o/2+this.rr+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr),this.rr,0,2*Math.PI);
var tem=new Point(this.o/2+this.rr+i*(this.o+2*this.rr),this.o/2+this.rr+j*(this.o+2*this.rr));
if (that.pList.length < 9)
this.pList.push(tem);
}
}
this.$ctx.stroke();
this.initImg=this.$ctx.getImageData(0,0,this.options.width,this.options.height);
};
this.initDraw();
//this.$ctx.stroke();
this.isIn=function(x,y){

for (var p in that.pList){
//console.log(that.pList[p][x]);
// console.log(( Math.pow((x-that.pList[p][x]),2)+Math.pow((y-that.pList[p][y]),2)));
if(( Math.pow((x-that.pList[p]["x"]),2)+Math.pow((y-that.pList[p]["y"]),2) ) < Math.pow(this.rr,2)){
return that.pList[p];
}
}
return 0;
};

this.pointDraw =function(c){
if (arguments.length>0){
that.$ctx.strokeStyle=c;
that.$ctx.fillStyle=c;
}
for (var p in that.sList){
that.$ctx.moveTo(that.sList[p]["x"]+that.pr,that.sList[p]["y"]);
that.$ctx.arc(that.sList[p]["x"],that.sList[p]["y"],that.pr,0,2*Math.PI);
that.$ctx.fill();
}
};
this.lineDraw=function (c){
if (arguments.length>0){
that.$ctx.strokeStyle=c;
that.$ctx.fillStyle=c;
}
if(that.sList.length > 0){
for( var p in that.sList){
if(p == 0){
console.log(that.sList[p]["x"],that.sList[p]["y"]);
that.$ctx.moveTo(that.sList[p]["x"],that.sList[p]["y"]);
continue;
}
that.$ctx.lineTo(that.sList[p]["x"],that.sList[p]["y"]);
console.log(that.sList[p]["x"],that.sList[p]["y"]);
}

}
};

this.allDraw =function(c){
if (arguments.length>0){
this.pointDraw(c);
this.lineDraw(c);
that.$ctx.stroke();
}
else {
this.pointDraw();
this.lineDraw();
}

};

this.draw=function(x,y){
that.$ctx.clearRect(0,0,that.options.width,that.options.height);
that.$ctx.beginPath();
//that.initDraw();
that.$ctx.putImageData(this.initImg,0,0);
that.$ctx.lineWidth=4;
that.pointDraw(that.options.lineColor);
that.lineDraw(that.options.lineColor);