-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw-circle.js
40 lines (36 loc) · 1.29 KB
/
draw-circle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class DrawingCircle extends PaintFunction{
constructor(contextReal){
super();
this.contextReal = contextReal;
this.contextDraft = contextDraft;
}
onMouseDown(coord,event){
this.contextDraft.strokeStyle = "#f44";
this.contextDraft.lineWidth = 5;
this.origX = coord[0];
this.origY = coord[1];
}
onDragging(coord,event){
this.contextDraft.strokeStyle = "#f44";
this.contextDraft.lineWidth = 5;
this.contextDraft.clearRect
(0,0,canvasDraft.width,canvasDraft.height);
this.contextDraft.beginPath();
this.contextDraft.arc
(this.origX, this.origY, Math.pow(Math.pow(this.origX - coord[0],2)+Math.pow(this.origY - coord[1],2),0.5),0,360 );
this.contextDraft.stroke();
}
onMouseMove(){ }
onMouseUp(coord){
this.contextReal.strokeStyle = "#f44";
this.contextReal.lineWidth = 5;
this.contextDraft.clearRect
(0,0,canvasDraft.width,canvasDraft.height);
this.contextReal.beginPath();
this.contextReal.arc
(this.origX, this.origY, Math.pow(Math.pow(this.origX - coord[0],2)+Math.pow(this.origY - coord[1],2),0.5),0,360 );
this.contextReal.stroke();
}
onMouseLeave(){ }
onMouseEnter(){ }
}