-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
185 lines (162 loc) · 4.96 KB
/
script.js
File metadata and controls
185 lines (162 loc) · 4.96 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/******************************************
* JSAnimation2 - Portfolio Intro
* Coleman Swarts
* Due Feb 13, 2025
* CSCI 324
* main javascript file
******************************************/
const canvas = document.getElementById("particleCanvas");
const ctx = canvas.getContext("2d");
// Set canvas size
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const particlesArray = [];
const numParticles = 120;
const mouse = { x: null, y: null, radius: 100 }; // Bigger radius for better effect
// Particle class with movement & interaction
class Particle {
constructor(x, y, size, speedX, speedY) {
this.x = x;
this.y = y;
this.size = size;
this.speedX = speedX;
this.speedY = speedY;
}
draw() {
ctx.fillStyle = "#00ff99";
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
update() {
this.x += this.speedX;
this.y += this.speedY;
// Bounce off walls
if (this.x + this.size > canvas.width || this.x - this.size < 0) {
this.speedX = -this.speedX;
}
if (this.y + this.size > canvas.height || this.y - this.size < 0) {
this.speedY = -this.speedY;
}
// Mouse interaction (particles repel)
const dx = mouse.x - this.x;
const dy = mouse.y - this.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < mouse.radius) {
let angle = Math.atan2(dy, dx);
this.x -= Math.cos(angle) * 3;
this.y -= Math.sin(angle) * 3;
}
this.draw();
}
}
// Create particles
function initParticles() {
particlesArray.length = 0;
for (let i = 0; i < numParticles; i++) {
let size = Math.random() * 3 + 1;
let x = Math.random() * canvas.width;
let y = Math.random() * canvas.height;
let speedX = (Math.random() - 0.5) * 2;
let speedY = (Math.random() - 0.5) * 2;
particlesArray.push(new Particle(x, y, size, speedX, speedY));
}
}
// Draw connections between particles
function connectParticles() {
for (let a = 0; a < particlesArray.length; a++) {
for (let b = a; b < particlesArray.length; b++) {
let dx = particlesArray[a].x - particlesArray[b].x;
let dy = particlesArray[a].y - particlesArray[b].y;
let distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
ctx.strokeStyle = "rgba(0, 255, 153, 0.2)";
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(particlesArray[a].x, particlesArray[a].y);
ctx.lineTo(particlesArray[b].x, particlesArray[b].y);
ctx.stroke();
}
}
}
}
// Animate particles
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let particle of particlesArray) {
particle.update();
}
connectParticles();
requestAnimationFrame(animate);
}
// Track Mouse Movement
window.addEventListener("mousemove", (event) => {
mouse.x = event.x;
mouse.y = event.y;
});
// Update on Resize
window.addEventListener("resize", () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
initParticles();
});
// Initialize and start animation
initParticles();
animate();
// ==========================
// Fake Code Loading
// ==========================
const fakeCode = [
"Initializing AI...",
"Loading modules...",
"Connecting to server...",
"Fetching user data...",
"Decryption sequence...",
"Verifying identity...",
"Access granted.",
];
const fakeCodeElement = document.getElementById("fake-code");
let fakeIndex = 0;
function showFakeCode() {
if (fakeIndex < fakeCode.length) {
fakeCodeElement.innerHTML += `<p>${fakeCode[fakeIndex]}</p>`;
fakeIndex++;
setTimeout(showFakeCode, 400);
} else {
setTimeout(typeEffect, 1000);
}
}
// ==========================
// Terminal Typing Effect
// ==========================
const text = " Hello, I'm a Programmer_";
const typedText = document.getElementById("typed-text");
const enterText = document.getElementById("enter-text");
let index = 0;
function typeEffect() {
if (index < text.length) {
typedText.innerHTML += text.charAt(index);
index++;
setTimeout(typeEffect, Math.random() * 150 + 50);
} else {
// Show "Press ENTER to Continue"
enterText.classList.remove("hidden");
}
}
setTimeout(showFakeCode, 1000);
// ==========================
// Press ENTER to Continue
// ==========================
document.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
enterText.innerHTML = "[Loading...]";
setTimeout(() => {
document.querySelector(".terminal").style.opacity = "0";
setTimeout(() => {
document.querySelector(".terminal").style.display = "none";
document.getElementById("main-content").style.display = "block";
window.scrollTo({ top: window.innerHeight, behavior: "smooth" });
}, 500);
}, 500);
}
});