-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainroot.js
102 lines (64 loc) · 1.91 KB
/
mainroot.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
$(document).ready(init);
var init = ( function() {
var canvasPad ;
var arrx = [];
var arry = [];
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
}
var drawpad = function() {
canvasPad = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
//myAudioContext = new AudioContext() ;
drawpad.setupEventListeners();
};
drawpad.setupEventListeners = function() {
document.body.addEventListener('touchmove', function(event) {
event.preventDefault();
}, false);
canvasPad.addEventListener('mousedown' , drawpad.clicking)
canvasPad.addEventListener('mouseup' , drawpad.lettingGo)
canvasPad.addEventListener('mouseleave' , drawpad.lettingGo)
}
drawpad.clicking = function(event) {
var xCoord = (event.x - this.offsetLeft)
var yCoord = (event.y - this.offsetTop)
ctx.beginPath();
// ctx.moveTo( xCoord , yCoord )
// ctx.lineTo ( xCoord+1 , yCoord+1 )
ctx.lineWidth = 10.0 ;
ctx.strokeStyle = '#CC0000';
// ctx.stroke()
canvasPad.addEventListener('mousemove' , drawpad.movingOn )
canvasPad.addEventListener('mouseout' , drawpad.lettingGo)
}
drawpad.lettingGo = function (event) {
console.log(arrx)
console.log(arry)
canvasPad.removeEventListener('mouseout' , drawpad.lettingGo)
canvasPad.removeEventListener('mousemove' , drawpad.movingOn)
}
drawpad.calculateVector = function (x,y) {
arrx.push(x);
arry.push(y);
drawpad.draw();
}
drawpad.draw = function(event) {
ctx.clearRect ( 0 , 0 , ctx.canvas.width , ctx.canvas.height);
ctx.strokeStyle = '#df4b26';
ctx.lineJoin = 'round' ;
ctx.lineWidth = 5;
for (var i=0 ; i<arrx.length ; i++) {
ctx.beginPath();
ctx.moveTo(arrx[i-1] , arry[i-1])
ctx.lineTo(arrx[i] , arry[i]) ;
ctx.closePath();
ctx.stroke();
}
}
drawpad.movingOn = function(event) {
drawpad.calculateVector ( event.x , event.y )
}
return drawpad();
})();