-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperc-circles.html
59 lines (57 loc) · 2.13 KB
/
perc-circles.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#candle{margin-left:auto;margin-right:auto;text-align:center;}
h1{text-align:center;color:red;text-shadow:2px 2px 8px olive;}
</style>
</head>
<body>
<div id="candle">
<h1>Animated Percentage Circles with JavaScript</h1>
<div style="width:600px;;margin-left:auto;margin-right:auto;">
<canvas id="canvas" width="400" class="img-responsive" height="400">
</canvas>
<p> </p>
</div>
<canvas id="Canvas_One" width="400" class="img-responsive" height="300" style=""></canvas>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
//Declare variables for the angle, increment and percentage
var a = 0, b = 5, d;
function draw() {
a = a + b;
if (a == 360) { a = 0; }
c = Math.PI * a / 180;
d = Math.round(100 * a / 360);
context.clearRect(0, 0, 500, 500);
context.beginPath();
context.lineWidth = 25;
context.strokeStyle = '#343434';
//Draw a dark static circle
context.arc(200, 200, 100, 0, 2 * Math.PI, false);
context.stroke();
//Display the percentage
context.beginPath();
context.font = 'bold 30pt Calibri';
context.fillText(d + '%', 180, 210);
context.fillStyle = "olive";
context.fill();
//Draw the dynamic circle
context.beginPath();
context.arc(200, 200, 100, 0, c, false);
//Gradient for the dynamic circle
var grd = context.createRadialGradient(200, 200, 102, 200, 200, 104);
grd.addColorStop(0, 'lemonchiffon');
grd.addColorStop(1, 'olive');
context.strokeStyle = grd;
context.stroke();
}
//Call the function every in 150 milliseconds
window.setInterval(draw, 150);
</script>
</div>
</body>
</html>