-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
141 lines (122 loc) · 3.51 KB
/
index.html
File metadata and controls
141 lines (122 loc) · 3.51 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Text Morphing Explosion - Andre Python</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@700&display=swap');
html, body {
margin: 0;
padding: 0;
overflow: hidden;
background: #202124; /* Google dark theme */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: 'Roboto Mono', monospace;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let width, height;
function resize() {
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
}
resize();
window.addEventListener('resize', resize);
const offCanvas = document.createElement('canvas');
const offCtx = offCanvas.getContext('2d');
// Three words now
const words = ["Welcome", "Bienvenue", "欢迎"];
let currentWordIndex = 0;
offCanvas.width = 1000;
offCanvas.height = 1000;
function getImageDataFromText(text) {
// Adjust font size for Chinese so it looks balanced
let fontSize = (text === "欢迎") ? 240 : 180;
offCtx.clearRect(0, 0, offCanvas.width, offCanvas.height);
offCtx.font = `bold ${fontSize}px 'Roboto Mono', monospace`;
offCtx.fillStyle = 'white';
offCtx.textBaseline = 'middle';
offCtx.textAlign = 'center';
offCtx.fillText(text, offCanvas.width / 2, offCanvas.height / 2);
return offCtx.getImageData(0, 0, offCanvas.width, offCanvas.height);
}
const PARTICLE_SIZE = 3.5;
const GAP = 7;
let particles = [];
function createParticlesFromText(text) {
const imageData = getImageDataFromText(text);
const newParticles = [];
for (let y = 0; y < offCanvas.height; y += GAP) {
for (let x = 0; x < offCanvas.width; x += GAP) {
const index = (y * offCanvas.width + x) * 4;
if (imageData.data[index + 3] > 128) {
const posX = x + (width - offCanvas.width) / 2;
const posY = y + (height - offCanvas.height) / 2;
newParticles.push({
x: Math.random() * width,
y: Math.random() * height,
tx: posX,
ty: posY,
vx: 0,
vy: 0,
colorLightness: Math.random() * 50 + 30
});
}
}
}
particles = newParticles;
}
createParticlesFromText(words[currentWordIndex]);
function morphToNextWord() {
// Explosion effect
particles.forEach(p => {
p.vx = (Math.random() - 0.5) * 10;
p.vy = (Math.random() - 0.5) * 10;
});
setTimeout(() => {
currentWordIndex = (currentWordIndex + 1) % words.length;
createParticlesFromText(words[currentWordIndex]);
}, 5000); // explosion pause longer
}
function animate() {
// Ghost trail effect
ctx.fillStyle = 'rgba(32, 33, 36, 0.2)';
ctx.fillRect(0, 0, width, height);
particles.forEach(p => {
// Slow morph after explosion
const dx = p.tx - p.x;
const dy = p.ty - p.y;
p.vx += dx * 0.007; // slower approach
p.vy += dy * 0.007;
p.vx *= 0.75;
p.vy *= 0.75;
p.x += p.vx;
p.y += p.vy;
// Blue hue shift (light to dark)
p.colorLightness += 0.15; // slower shift
if (p.colorLightness > 100) p.colorLightness = 30;
ctx.fillStyle = `hsl(200, 100%, ${p.colorLightness}%)`;
ctx.beginPath();
ctx.arc(p.x, p.y, PARTICLE_SIZE, 0, Math.PI * 3);
ctx.fill();
});
requestAnimationFrame(animate);
}
animate();
setInterval(morphToNextWord, 7000); // slower word changes
</script>
</body>
</html>