-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (105 loc) · 3.81 KB
/
Copy pathscript.js
File metadata and controls
132 lines (105 loc) · 3.81 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
const starsContainer = document.querySelector('.stars');
const numStars = 300;
for (let i = 0; i < numStars; i++) {
const star = document.createElement('div');
star.classList.add('star');
const size = Math.random() * 2 + 1;
star.style.width = size + 'px';
star.style.height = size + 'px';
star.style.top = Math.random() * 100 + 'vh';
star.style.left = Math.random() * 100 + 'vw';
starsContainer.appendChild(star);
}
const loader = document.getElementById("loader");
const sun = document.getElementById("sun");
const sunPlaceholder = document.getElementById("sun-placeholder");
const welcomeText = document.getElementById("welcome-text");
const numCircles = 8;
const initialRadius = 120;
const circles = [];
let mouseX = null;
let mouseY = null;
let currentAngle = 0;
const rotationSpeed = 0.005;
const escapeRadius = 150;
const planetClasses = [
"planet-mercury", "planet-venus", "planet-earth", "planet-mars",
"planet-jupiter", "planet-saturn", "planet-uranus", "planet-neptune"
];
for (let i = 0; i < numCircles; i++) {
const circle = document.createElement("div");
circle.className = `circle ${planetClasses[i]}`;
loader.appendChild(circle);
circles.push({
el: circle,
initialAngleOffset: (i / numCircles) * Math.PI * 2,
isScattered: false,
scatteredX: 0,
scatteredY: 0
});
}
const fill = document.getElementById('fill');
let progress = 0;
let finished = false;
function getSunSize() {
if (window.innerWidth <= 480) return '6vw';
if (window.innerWidth <= 768) return '7vw';
return '60px';
}
function animate() {
if (finished) return;
currentAngle += rotationSpeed;
const loaderRect = loader.getBoundingClientRect();
const centerX = loaderRect.left + loaderRect.width / 2;
const centerY = loaderRect.top + loaderRect.height / 2;
circles.forEach(circleObj => {
let angle = circleObj.initialAngleOffset + currentAngle;
let x = Math.cos(angle) * initialRadius;
let y = Math.sin(angle) * initialRadius;
if (mouseX !== null && mouseY !== null) {
const dx = centerX + x - mouseX;
const dy = centerY + y - mouseY;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < escapeRadius) {
if (!circleObj.isScattered) {
circleObj.isScattered = true;
circleObj.scatteredX = (Math.random() - 0.5) * window.innerWidth;
circleObj.scatteredY = (Math.random() - 0.5) * window.innerHeight;
}
} else {
circleObj.isScattered = false;
}
} else {
circleObj.isScattered = false;
}
if (circleObj.isScattered) {
x = circleObj.scatteredX;
y = circleObj.scatteredY;
}
circleObj.el.style.transform = `translate(${x}px, ${y}px)`;
});
if (progress < 100) {
progress += 0.1;
fill.style.height = progress + '%';
} else {
finished = true;
circles.forEach(c => c.el.style.display = 'none');
sun.style.position = 'static';
sun.style.margin = '0 10px';
sun.classList.add("in-text");
document.getElementById('fill').style.display = 'none';
sun.style.width = getSunSize();
sun.style.height = getSunSize();
sunPlaceholder.appendChild(sun);
welcomeText.classList.add('show');
setTimeout(() => {
document.getElementById('solar-text').classList.add('show');
}, 1500);
}
requestAnimationFrame(animate);
}
document.addEventListener("mousemove", e => {
mouseX = e.clientX;
mouseY = e.clientY;
});
animate();