-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
113 lines (96 loc) · 3.12 KB
/
index.html
File metadata and controls
113 lines (96 loc) · 3.12 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Quest Log</title>
<link rel="icon" href="Ellipse 1.png" />
<link rel="stylesheet" href="styles.css" />
</head>
<body class="home">
<canvas id="star-trail-canvas"></canvas>
<img
class="background-image"
src="https://opengameart.org/sites/default/files/5_69.png"
/>
<div class="home-container">
<h1>Quest Log</h1>
<p>Your tasks, but make them an adventure.</p>
<a href="quest.html" class="start-button">Start questing</a>
</div>
<script>
// Shooting star trail effect
const canvas = document.getElementById("star-trail-canvas");
const ctx = canvas.getContext("2d");
// Set canvas size to cover the entire viewport
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener("resize", resizeCanvas);
// Mouse tracking variables
let mouseX = 0;
let mouseY = 0;
let prevMouseX = 0;
let prevMouseY = 0;
let trailLength = 0;
// Store trail segments for fading effect
let trailSegments = [];
// Track mouse movement
document.addEventListener("mousemove", (e) => {
prevMouseX = mouseX;
prevMouseY = mouseY;
mouseX = e.clientX;
mouseY = e.clientY;
// Calculate distance moved (speed)
const distance = Math.sqrt(
Math.pow(mouseX - prevMouseX, 2) + Math.pow(mouseY - prevMouseY, 2),
);
// Set trail length based on movement speed
trailLength = Math.min(distance * 2, 50); // Max length of 100px
// Add new trail segment if there's movement
if (trailLength > 1) {
trailSegments.push({
x1: prevMouseX,
y1: prevMouseY,
x2: mouseX,
y2: mouseY,
opacity: 1.0,
life: 30, // frames to live
});
// 🔒 Cap the trail length
if (trailSegments.length > 3) {
trailSegments.shift(); // remove oldest
}
}
});
// Animation loop
function animate() {
// Clear canvas completely
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update and draw trail segments
for (let i = trailSegments.length - 1; i >= 0; i--) {
const segment = trailSegments[i];
// Decrease life and opacity
segment.life--;
segment.opacity = segment.life / 50; // Fade over 30 frames
// Remove dead segments
if (segment.life <= 0) {
trailSegments.splice(i, 1);
continue;
}
// Draw segment with current opacity
ctx.strokeStyle = `rgba(255, 255, 255, ${segment.opacity})`;
ctx.lineWidth = 2;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(segment.x1, segment.y1);
ctx.lineTo(segment.x2, segment.y2);
ctx.stroke();
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>