forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
160 lines (130 loc) · 3.93 KB
/
index.html
File metadata and controls
160 lines (130 loc) · 3.93 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!-- Hi this is simple digital clock with glowing effect made with a little css and js -->
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body class="dark-theme || light-theme">
<canvas id="canvas"></canvas>
<div class="center">
<button class=" btn-toggle">Toggle Dark Mode</button>
<div class="wrapper">
<div class="display">
<div class="timezone">
<select name="TimeZone" id="TimeZone">
</select>
</div>
<div id="time"></div>
</div>
</div>
</div>
main
<script src="script.js"></script>
<script>
// Select the button
const btn = document.querySelector('.btn-toggle');
// Listen for a click on the button
btn.addEventListener('click', function() {
// Then toggle (add/remove) the .dark-theme class to the body
document.body.classList.toggle('dark-theme');
})
console.log("Hello World");
var canvas = document.getElementById("canvas");
var c = canvas.getContext("2d");
var tx = window.innerWidth;
var ty = window.innerHeight;
canvas.width = tx;
canvas.height = ty;
//c.lineWidth= 5;
//c.globalAlpha = 0.5;
var mousex = 0;
var mousey = 0;
addEventListener("mousemove", function() {
mousex = event.clientX;
mousey = event.clientY;
});
var grav = 0.99;
c.strokeWidth=5;
function randomColor() {
return (
"rgba(" +
Math.round(Math.random() * 250) +
"," +
Math.round(Math.random() * 250) +
"," +
Math.round(Math.random() * 250) +
"," +
Math.ceil(Math.random() * 10) / 10 +
")"
);
}
function Ball() {
this.color = randomColor();
this.radius = Math.random() * 20 + 14;
this.startradius = this.radius;
this.x = Math.random() * (tx - this.radius * 2) + this.radius;
this.y = Math.random() * (ty - this.radius);
this.dy = Math.random() * 2;
this.dx = Math.round((Math.random() - 0.5) * 10);
this.vel = Math.random() /5;
this.update = function() {
c.beginPath();
c.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
c.fillStyle = this.color;
c.fill();
//c.stroke();
};
}
var bal = [];
for (var i=0; i<50; i++){
bal.push(new Ball());
}
function animate() {
if (tx != window.innerWidth || ty != window.innerHeight) {
tx = window.innerWidth;
ty = window.innerHeight;
canvas.width = tx;
canvas.height = ty;
}
requestAnimationFrame(animate);
c.clearRect(0, 0, tx, ty);
for (var i = 0; i < bal.length; i++) {
bal[i].update();
bal[i].y += bal[i].dy;
bal[i].x += bal[i].dx;
if (bal[i].y + bal[i].radius >= ty) {
bal[i].dy = -bal[i].dy * grav;
} else {
bal[i].dy += bal[i].vel;
}
if(bal[i].x + bal[i].radius > tx || bal[i].x - bal[i].radius < 0){
bal[i].dx = -bal[i].dx;
}
if(mousex > bal[i].x - 20 &&
mousex < bal[i].x + 20 &&
mousey > bal[i].y -50 &&
mousey < bal[i].y +50 &&
bal[i].radius < 70){
//bal[i].x += +1;
bal[i].radius +=5;
} else {
if(bal[i].radius > bal[i].startradius){
bal[i].radius += -5;
}
}
//forloop end
}
//animation end
}
animate();
setInterval(function() {
bal.push(new Ball());
bal.splice(0, 1);
}, 400);
</script>
</body>
</html>