-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawLines.js
More file actions
46 lines (39 loc) · 963 Bytes
/
DrawLines.js
File metadata and controls
46 lines (39 loc) · 963 Bytes
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
41
42
43
var mousePressed = false;
var lastX, lastY;
var ctx;
function InitThis() {
ctx = document.getElementById("bbCanvas").getContext("2d");
$("#bbCanvas").mousedown(function(e){
mousePressed= true;
Draw(e.pageX -$(this).offset().left, e.pageY - $(this).offset().top, false);
});
$("#bbCanvas").mousemove(function(e){
if(mousePressed){
Draw(e.pageX-$(this).offset().left, e.pageY - $(this).offset().top, true);
}
});
$("#bbCanvas").mouseup(function(e){
mousePressed = false;
});
$("#bbCanvas").mouseleave(function(e){
mousePressed = false;
});
}
function Draw(x,y, isDown) {
if(isDown) {
ctx.beginPath();
ctx.strokeStyle = $("#selColor").val();
ctx.lineWidth = $("#selWidth").val();
ctx.lineJoin ="round";
ctx.moveTo(lastX, lastY);
ctx.lineTo(x,y);
ctx.closePath();
ctx.stroke();
}
lastX =x;
lastY =y;
}
function clearArea(){
ctx.setTransform(1,0,0,1,0,0);
ctx.clearRect(0,0, ctx.canvas.width, ctx.canvas.height);
}