mgbam commited on
Commit
b32bc19
·
verified ·
1 Parent(s): 0e8637e

Update genesis/static/animation.js

Browse files
Files changed (1) hide show
  1. genesis/static/animation.js +43 -0
genesis/static/animation.js CHANGED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const canvas = document.getElementById('molecule-canvas');
2
+ const ctx = canvas.getContext('2d');
3
+ canvas.width = window.innerWidth;
4
+ canvas.height = window.innerHeight;
5
+
6
+ let particles = [];
7
+
8
+ for (let i = 0; i < 120; i++) {
9
+ particles.push({
10
+ x: Math.random() * canvas.width,
11
+ y: Math.random() * canvas.height,
12
+ r: Math.random() * 3,
13
+ dx: (Math.random() - 0.5) * 1,
14
+ dy: (Math.random() - 0.5) * 1
15
+ });
16
+ }
17
+
18
+ function draw() {
19
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
20
+ ctx.fillStyle = '#00ff9d';
21
+ particles.forEach(p => {
22
+ ctx.beginPath();
23
+ ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
24
+ ctx.fill();
25
+ });
26
+ }
27
+
28
+ function update() {
29
+ particles.forEach(p => {
30
+ p.x += p.dx;
31
+ p.y += p.dy;
32
+ if (p.x < 0 || p.x > canvas.width) p.dx *= -1;
33
+ if (p.y < 0 || p.y > canvas.height) p.dy *= -1;
34
+ });
35
+ }
36
+
37
+ function loop() {
38
+ draw();
39
+ update();
40
+ requestAnimationFrame(loop);
41
+ }
42
+
43
+ loop();