89 lines
1.9 KiB
HTML
Executable File
89 lines
1.9 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Snowfall Fun</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: black;
|
|
color: white;
|
|
font-family: monospace;
|
|
}
|
|
#controls {
|
|
position: fixed;
|
|
top: 10px;
|
|
left: 10px;
|
|
z-index: 1000;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="controls">
|
|
<label for="countSlider">Snow Amount: </label>
|
|
<input type="range" id="countSlider" min="10" max="500" value="100">
|
|
<span id="countValue">100</span>
|
|
</div>
|
|
|
|
<canvas id="snowCanvas"></canvas>
|
|
|
|
<script>
|
|
const canvas = document.getElementById('snowCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
let snowflakes = [];
|
|
let snowCount = 100;
|
|
|
|
function createSnowflakes(count) {
|
|
snowflakes = [];
|
|
for (let i = 0; i < count; i++) {
|
|
snowflakes.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
char: '.',
|
|
speed: Math.random() * 2 + 1
|
|
});
|
|
}
|
|
}
|
|
|
|
function drawSnowflakes() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
ctx.fillStyle = 'white';
|
|
ctx.font = "20px monospace";
|
|
for (let flake of snowflakes) {
|
|
ctx.fillText(flake.char, flake.x, flake.y);
|
|
flake.y += flake.speed;
|
|
if (flake.y > canvas.height) {
|
|
flake.y = 0;
|
|
flake.x = Math.random() * canvas.width;
|
|
}
|
|
}
|
|
requestAnimationFrame(drawSnowflakes);
|
|
}
|
|
|
|
const slider = document.getElementById('countSlider');
|
|
const countValue = document.getElementById('countValue');
|
|
slider.addEventListener('input', () => {
|
|
snowCount = parseInt(slider.value);
|
|
countValue.textContent = snowCount;
|
|
createSnowflakes(snowCount);
|
|
});
|
|
|
|
window.addEventListener('resize', () => {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
createSnowflakes(snowCount);
|
|
});
|
|
|
|
createSnowflakes(snowCount);
|
|
drawSnowflakes();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|