Below is a simple HTML code for a single-page screensaver that creates a mesmerizing animation using geometric shapes and colors. You can simply copy and paste this code into an HTML file and open it in a browser to see the effect:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Screensaver</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="screensaverCanvas"></canvas>
<script>
const canvas = document.getElementById('screensaverCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const shapes = [];
const numShapes = 100;
// Generate random shapes
for (let i = 0; i < numShapes; i++) {
const size = Math.random() * 30 + 10;
const x = Math.random() * canvas.width;
const y = Math.random() * canvas.height;
const dx = (Math.random() - 0.5) * 4;
const dy = (Math.random() - 0.5) * 4;
const color = `hsl(${Math.random() * 360}, 100%, 50%)`;
shapes.push({ x, y, size, dx, dy, color });
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
shapes.forEach(shape => {
ctx.fillStyle = shape.color;
ctx.beginPath();
ctx.arc(shape.x, shape.y, shape.size, 0, Math.PI * 2);
ctx.fill();
// Update position
shape.x += shape.dx;
shape.y += shape.dy;
// Bounce off walls
if (shape.x + shape.size > canvas.width || shape.x - shape.size < 0) shape.dx = -shape.dx;
if (shape.y + shape.size > canvas.height || shape.y - shape.size < 0) shape.dy = -shape.dy;
});
requestAnimationFrame(draw);
}
draw();
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
</script>
</body>
</html>
How to Use:
- Open your text editor (such as Notepad, VS Code, etc.).
- Copy and paste the provided HTML code into the editor.
- Save the file with a
.html extension (for example, screensaver.html).
- Open the saved HTML file in a web browser.
This screensaver will display colorful bouncing circles that change positions randomly across the screen. The colors are bright and vibrant, creating a visually appealing effect without any text. Enjoy!