Add animated matrix background effect to home page.
This commit is contained in:
+3
-1
@@ -6,6 +6,7 @@
|
||||
<link rel="stylesheet" href="styles_home.css">
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="matrix-canvas"></canvas>
|
||||
<button class="logout" id="logout">Logout</button>
|
||||
<div class="balance">
|
||||
Balance: $<span id="balance">0</span>
|
||||
@@ -15,7 +16,7 @@
|
||||
<button id="join">Join Lobby</button>
|
||||
</div>
|
||||
<div id="join-form" class="hidden">
|
||||
<input type="text" id="join-code" placeholder="Enter Lobby ID" />
|
||||
<input type="text" id="join-code" placeholder="Enter Lobby ID"/>
|
||||
<button id="submit-join">Join</button>
|
||||
</div>
|
||||
<div id="join-error" class="error-message hidden"></div>
|
||||
@@ -28,4 +29,5 @@
|
||||
</div>
|
||||
</body>
|
||||
<script src="frontend_home.js" defer></script>
|
||||
<script src="matrix.js"></script>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
const canvas = document.getElementById("matrix-canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
const letters = "アァイィウヴエェオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
|
||||
const fontSize = 16;
|
||||
const columns = Math.floor(canvas.width / fontSize);
|
||||
const drops = new Array(columns).fill(1);
|
||||
function drawMatrix() {
|
||||
ctx.fillStyle = "rgba(0, 0, 0, 0.2)";
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = "#39FF14";
|
||||
ctx.font = fontSize + "px monospace";
|
||||
for (let i = 0; i < drops.length; i++) {
|
||||
const text = letters[Math.floor(Math.random() * letters.length)];
|
||||
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
|
||||
if (drops[i] * fontSize > canvas.height || Math.random() > 0.975) {
|
||||
drops[i] = 0;
|
||||
}
|
||||
drops[i]++;
|
||||
}
|
||||
}
|
||||
setInterval(drawMatrix, 50);
|
||||
window.addEventListener("resize", () => {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
});
|
||||
@@ -126,3 +126,14 @@ button.logout {
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#matrix-canvas {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: -1;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: transparent;
|
||||
pointer-events: none;
|
||||
}
|
||||
Reference in New Issue
Block a user