-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
149 lines (126 loc) · 3.86 KB
/
background.js
File metadata and controls
149 lines (126 loc) · 3.86 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
const canvas = document.getElementById('network');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const numDots = 100;
const dots = [];
function Dot(x, y, radius) {
this.x = x;
this.y = y;
this.radius = radius;
this.velocity = {
x: (Math.random() - 0.5) * 1,
y: (Math.random() - 0.5) * 1
};
}
Dot.prototype.draw = function () {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fillStyle = '#fff';
ctx.fill();
}
Dot.prototype.update = function () {
this.x += this.velocity.x;
this.y += this.velocity.y;
if (this.x + this.radius > canvas.width || this.x - this.radius < 0) {
this.velocity.x = -this.velocity.x;
}
if (this.y + this.radius > canvas.height || this.y - this.radius < 0) {
this.velocity.y = -this.velocity.y;
}
this.draw();
}
for (let i = 0; i < numDots; i++) {
const radius = Math.random() * 3 + 1;
const x = Math.random() * (canvas.width - radius * 2) + radius;
const y = Math.random() * (canvas.height - radius * 2) + radius;
dots.push(new Dot(x, y, radius));
}
function connectDots() {
for (let i = 0; i < dots.length; i++) {
for (let j = i; j < dots.length; j++) {
const dx = dots[i].x - dots[j].x;
const dy = dots[i].y - dots[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 80) {
ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(dots[i].x, dots[i].y);
ctx.lineTo(dots[j].x, dots[j].y);
ctx.stroke();
}
}
}
}
function areAllDotsConnected() {
for (let i = 0; i < dots.length; i++) {
for (let j = 0; j < dots.length; j++) {
if (i !== j) {
const dx = dots[i].x - dots[j].x;
const dy = dots[i].y - dots[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance >= 80) {
return false;
}
}
}
}
return true;
}
let allConnected = false;
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
dots.forEach(dot => {
dot.update();
});
connectDots();
if (areAllDotsConnected()) {
allConnected = true;
titleElement.textContent = "Yay you did it!";
}
}
canvas.addEventListener('mousemove', (event) => {
const mouseX = event.clientX;
const mouseY = event.clientY;
dots.forEach(dot => {
const dx = mouseX - dot.x;
const dy = mouseY - dot.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
dot.velocity.x = dx / 100;
dot.velocity.y = dy / 100;
}
});
});
// Typing effect for the title
const titleElement = document.querySelector('.title');
const titleText = "I'm Aeon, I make stuff.";
let i = 0;
let isTyping = true;
function animateTitle() {
if (isTyping) {
titleElement.textContent = titleText.slice(0, i);
i++;
if (i > titleText.length) {
isTyping = false;
i = titleText.length;
setTimeout(animateTitle, 1000); // Wait for a few seconds before untyping
} else {
setTimeout(animateTitle, 50); // Adjust typing speed by changing the timeout
}
} else {
titleElement.textContent = titleText.slice(0, i);
i--;
if (i < 0) {
isTyping = true;
i = 0;
setTimeout(animateTitle, 1000); // Wait for a few seconds before typing
} else {
setTimeout(animateTitle, 100); // Adjust untyping speed by changing the timeout
}
}
}
animate();
animateTitle();