forked from alimd/CanvasLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvasLoader.js
79 lines (65 loc) · 1.51 KB
/
CanvasLoader.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
// a callibrate func for change range of numbers
Math.getInRange=function (x, arr) {// arr = [x1,x2,y1,y2] // x is input and new y return
return ((arr[3] - arr[2]) * (x - arr[0])) / (arr[1] - arr[0]) + arr[2];
}
$(function(){
var canvas = $('#loading')[0],
ctx = canvas.getContext("2d"),
d2r = Math.PI/180,
degshif = 90,
currentDegree = 0,
aniDue = 4000,
lastDraw = 0,
iv=0,
saresh = 6*d2r,
starArc = -1*degshif*d2r;
var drawCircle = function (deg){
ctx.clearRect(0,0,40,40);
deg-=degshif;
deg*=d2r;
// sahdow
ctx.lineWidth=7;
ctx.globalAlpha=0.2;
ctx.strokeStyle='hsl(60,20%,20%)';
ctx.beginPath();
ctx.arc(20,20,15,0,360*d2r);
ctx.stroke();
if(!deg) return;
// body
ctx.lineWidth=5;
ctx.globalAlpha=0.8;
//ctx.strokeStyle='hsl(60,10%,20%)';
ctx.beginPath();
ctx.arc(20,20,15,starArc,deg-saresh);
ctx.stroke();
// saresh
ctx.beginPath();
ctx.strokeStyle='hsl(60,5%,70%)';
ctx.arc(20,20,15,deg-saresh,deg);
ctx.stroke();
//ctx.closePath();
},
circleAni = function(){
var now = Date.now();
currentDegree += Math.getInRange(now-lastDraw,[0,aniDue,0,360]);
if(currentDegree>359){
currentDegree%=360;
console.log('nextSlide');
}
drawCircle(currentDegree);
lastDraw = now;
},
startInt = function(){
if(iv) return;
lastDraw = Date.now();
iv = setInterval(circleAni,1000/60);
},
stopInt = function(){
clearInterval(iv);
iv=0;
}
$('#draw').click(circleAni);
$('#start').click(startInt);
$('#stop').click(stopInt);
startInt();
});