-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcandle.html
100 lines (92 loc) · 3.17 KB
/
candle.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
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
<!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 rgb(19, 18, 18);}
h2{text-align:center;color:olive;text-shadow:2px 2px 8px rgb(24, 23, 23);}
</style>
</head>
<body>
<div id="candle">
<h1>The Candle</h1>
<h2>HTML5 Canvas</h2>
<canvas id="Canvas_One" width="400" class="img-responsive" height="300" style=""></canvas>
<br /><br />
<input type="button" value="Light Up" onclick="window.setInterval('drawing()',10)" />
<script type="text/javascript">
var canvas = document.getElementById('Canvas_One');
var context = canvas.getContext('2d');
var a=0;var b=0.1;
// top of the candle
context.beginPath();
context.moveTo(190,150);
context.arc(200,150,22,0,Math.PI+0.1,false);
context.fillStyle='lightgrey';
context.fill();
// wax
context.beginPath()
context.moveTo(180,150);
context.rect(180,150,40,150);
context.fillStyle = 'lightgrey';
context.fill();
// the wick
context.beginPath();
context.moveTo(197,135);
context.fillStyle="black";
context.fill();
context.fillRect(197,135,5,15);
context.closePath();
function drawing(){
a=a+b;
if(a>=3){b=-0.1;}
if(a<=-3){b=0.1;}
// clear canvas
context.clearRect(0,0,400,300);
// top of the candle
context.beginPath();
context.moveTo(190,150);
context.arc(200,150,22,0,Math.PI+0.1,false);
context.fillStyle='lightgrey';
context.fill();
//yellow part of flame
context.beginPath();
context.moveTo(188,150);
context.quadraticCurveTo(200+a,18-a,212,150);
context.closePath();
context.fillStyle="#FFFE00";
context.fill();
//white part of flame
context.beginPath();
context.moveTo(193,150);
context.quadraticCurveTo(200+a,25-a,207,150);
context.closePath();
context.fillStyle="#E9DD00";
context.fill();
// blue part of flame
context.beginPath();
context.moveTo(194,150);
context.quadraticCurveTo(200+a,90+a,206,150);
context.fillStyle="rgba(0,0,255,0.8)";
context.fill();
// the wick
context.beginPath();
context.moveTo(197,135);
context.fillStyle="black";
context.fill();
context.fillRect(197,135,5,15);
context.closePath();
// wax
context.beginPath()
context.moveTo(180,150);
context.rect(180,150,40,150);
context.fillStyle = 'lightgrey';
context.fill();
}
</script>
</div>
<div id="pendulum">
</div>
</body>
</html>