-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigital_rain.html
More file actions
136 lines (113 loc) · 4.54 KB
/
digital_rain.html
File metadata and controls
136 lines (113 loc) · 4.54 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Rain Animation</title>
<style>
body {
margin: 0;
padding: 0;
background: #000;
overflow: hidden;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
background: #000;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Set canvas to full screen
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Characters for the rain effect
const characters = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const charArray = characters.split('');
// Column settings
const fontSize = 14;
const columns = canvas.width / fontSize;
// Array to store the y position of each drop
const drops = [];
// Initialize drops
for (let i = 0; i < columns; i++) {
drops[i] = Math.random() * canvas.height;
}
// Animation function
function draw() {
// Create trailing effect by drawing semi-transparent black rectangle
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Set text style
ctx.fillStyle = '#00ff00';
ctx.font = fontSize + 'px Courier New';
// Draw characters
for (let i = 0; i < drops.length; i++) {
// Random character
const char = charArray[Math.floor(Math.random() * charArray.length)];
// Draw character
ctx.fillText(char, i * fontSize, drops[i]);
// Move drop down
drops[i] += fontSize;
// Reset drop to top with some randomness
if (drops[i] > canvas.height && Math.random() > 0.975) {
drops[i] = 0;
}
}
}
// Handle window resize
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Recalculate columns
const newColumns = canvas.width / fontSize;
// Adjust drops array
drops.length = newColumns;
for (let i = 0; i < newColumns; i++) {
if (drops[i] === undefined) {
drops[i] = Math.random() * canvas.height;
}
}
});
// Start animation
setInterval(draw, 50);
// Add some interactivity - click to create burst
canvas.addEventListener('click', (e) => {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Create a burst effect at click location
const columnIndex = Math.floor(x / fontSize);
if (columnIndex >= 0 && columnIndex < drops.length) {
drops[columnIndex] = y;
// Affect nearby columns
for (let i = -3; i <= 3; i++) {
const nearbyColumn = columnIndex + i;
if (nearbyColumn >= 0 && nearbyColumn < drops.length) {
drops[nearbyColumn] = y + (Math.random() - 0.5) * 50;
}
}
}
});
// Easter egg: Press 'N' for Neo mode (faster, more intense)
let neoMode = false;
document.addEventListener('keydown', (e) => {
if (e.key.toLowerCase() === 'n') {
neoMode = !neoMode;
if (neoMode) {
document.body.style.background = '#001100';
console.log('Neo mode activated! "There is no spoon..."');
} else {
document.body.style.background = '#000';
console.log('Neo mode deactivated.');
}
}
});
</script>
</body>
</html>