-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.js
executable file
·60 lines (46 loc) · 1.27 KB
/
test.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
var c = document.getElementById('degcanvas')
var ctx = c.getContext('2d')
ctx.translate(150, 150);
var canw = 300
function draw (val) {
ctx.clearRect(-150,-150,c.width, c.height)
ctx.font = "48px serif";
ctx.textAlign = "center"
ctx.rotate(Math.PI);
ctx.fillText(val, 0, 0);
ctx.beginPath()
for (var i=0; i<= 180; i++) {
ctx.restore()
ctx.save()
if ( i > val / 360 * 180) {
ctx.fillStyle = '#FFF'
} else {
ctx.fillStyle = 'red'
}
if(i > 0) {
ctx.rotate(Math.PI * 2 / 180 * i);
} else {
//ctx.rotate(Math.PI);
}
ctx.fillRect(0, 100, 1, 40)
}
}
draw(0)
function move (event) {
var x = event.pageX - c.getBoundingClientRect().left;
var y = event.pageY - c.getBoundingClientRect().top;
var deg = 0
if (x > canw / 2) {
deg = (Math.min(1, y * 1.00 / canw)) * 180
} else {
deg = 180 + (Math.min(1, (canw - y)* 1.00 / canw)) * 180
}
console.log(deg, x,y)
draw(parseInt(deg))
}
c.addEventListener('mousedown', function(event) {
c.addEventListener('mousemove', move,false);
})
c.addEventListener('mouseup', function(event) {
c.removeEventListener('mousemove', move)
})