I'll create an interactive particle constellation visualization that responds to your mouse movements. This combines beautiful visuals with smooth animations and interactive effects.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quantum Constellation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #000;
overflow: hidden;
font-family: 'Arial', sans-serif;
cursor: none;
}
#canvas {
position: fixed;
top: 0;
left: 0;
z-index: 1;
}
.cursor {
position: fixed;
width: 20px;
height: 20px;
border: 2px solid rgba(255, 255, 255, 0.5);
border-radius: 50%;
pointer-events: none;
z-index: 9999;
transition: transform 0.1s ease;
mix-blend-mode: difference;
}
.cursor-follower {
position: fixed;
width: 40px;
height: 40px;
background: radial-gradient(circle, rgba(100, 200, 255, 0.3) 0%, transparent 70%);
border-radius: 50%;
pointer-events: none;
z-index: 9998;
transition: transform 0.3s ease;
}
.info {
position: fixed;
bottom: 20px;
left: 20px;
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
z-index: 10;
background: rgba(0, 0, 0, 0.5);
padding: 15px;
border-radius: 10px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.controls {
position: fixed;
top: 20px;
right: 20px;
z-index: 10;
display: flex;
gap: 10px;
}
button {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.3);
color: white;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
backdrop-filter: blur(10px);
transition: all 0.3s ease;
}
button:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(100, 200, 255, 0.3);
}
.stats {
position: fixed;
top: 20px;
left: 20px;
color: rgba(255, 255, 255, 0.7);
font-size: 12px;
z-index: 10;
font-family: monospace;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="cursor"></div>
<div class="cursor-follower"></div>
<div class="controls">
<button onclick="toggleGravity()">Toggle Gravity</button>
<button onclick="explodeParticles()">Explode</button>
<button onclick="resetParticles()">Reset</button>
</div>
<div class="stats">
<div>FPS: <span id="fps">60</span></div>
<div>Particles: <span id="particleCount">0</span></div>
</div>
<div class="info">
Move your mouse to interact • Click to attract particles • Hold to create gravity well
</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const cursor = document.querySelector('.cursor');
const cursorFollower = document.querySelector('.cursor-follower');
let width = window.innerWidth;
let height = window.innerHeight;
canvas.width = width;
canvas.height = height;
let mouse = { x: width / 2, y: height / 2, down: false };
let particles = [];
let connections = [];
let gravityEnabled = false;
let lastTime = 0;
let fps = 60;
class Particle {
constructor() {
this.x = Math.random() * width;
this.y = Math.random() * height;
this.vx = (Math.random() - 0.5) * 0.5;
this.vy = (Math.random() - 0.5) * 0.5;
this.radius = Math.random() * 2 + 1;
this.color = `hsl(${Math.random() * 60 + 180}, 70%, 60%)`;
this.pulsePhase = Math.random() * Math.PI * 2;
this.originalRadius = this.radius;
}
update() {
// Mouse interaction
const dx = mouse.x - this.x;
const dy = mouse.y - this.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 150) {
const force = (150 - distance) / 150;
if (mouse.down) {
// Attract
this.vx += dx * force * 0.02;
this.vy += dy * force * 0.02;
} else {
// Repel
this.vx -= dx * force * 0.01;
this.vy -= dy * force * 0.01;
}
}
// Gravity
if (gravityEnabled) {
this.vy += 0.05;
}
// Update position
this.x += this.vx;
this.y += this.vy;
// Damping
this.vx *= 0.99;
this.vy *= 0.99;
// Bounce off walls
if (this.x < this.radius || this.x > width - this.radius) {
this.vx *= -0.9;
this.x = Math.max(this.radius, Math.min(width - this.radius, this.x));
}
if (this.y < this.radius || this.y > height - this.radius) {
this.vy *= -0.9;
this.y = Math.max(this.radius, Math.min(height - this.radius, this.y));
}
// Pulse effect
this.pulsePhase += 0.05;
this.radius = this.originalRadius + Math.sin(this.pulsePhase) * 0.5;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fillStyle = this.color;
ctx.fill();
// Glow effect
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius * 2, 0, Math.PI * 2);
const gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.radius * 2);
gradient.addColorStop(0, this.color.replace('60%', '40%').replace(')', ', 0.3)'));
gradient.addColorStop(1, 'transparent');
ctx.fillStyle = gradient;
ctx.fill();
}
}
// Initialize particles
function createParticles() {
particles = [];
const count = Math.min(150, Math.floor((width * height) / 10000));
for (let i = 0; i < count; i++) {
particles.push(new Particle());
}
document.getElementById('particleCount').textContent = count;
}
// Draw connections between nearby particles
function drawConnections() {
connections = [];
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 120) {
const opacity = (1 - distance / 120) * 0.5;
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = `rgba(100, 200, 255, ${opacity})`;
ctx.lineWidth = opacity * 2;
ctx.stroke();
}
}
}
}
// Animation loop
function animate(currentTime) {
const deltaTime = currentTime - lastTime;
if (deltaTime > 0) {
fps = Math.round(1000 / deltaTime);
document.getElementById('fps').textContent = fps;
}
lastTime = currentTime;
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, width, height);
drawConnections();
particles.forEach(particle => {
particle.update();
particle.draw();
});
requestAnimationFrame(animate);
}
// Mouse events
window.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
cursor.style.left = e.clientX - 10 + 'px';
cursor.style.top = e.clientY - 10 + 'px';
cursorFollower.style.left = e.clientX - 20 + 'px';
cursorFollower.style.top = e.clientY - 20 + 'px';
});
window.addEventListener('mousedown', () => {
mouse.down = true;
cursor.style.transform = 'scale(0.8)';
cursorFollower.style.transform = 'scale(1.5)';
});
window.addEventListener('mouseup', () => {
mouse.down = false;
cursor.style.transform = 'scale(1)';
cursorFollower.style.transform = 'scale(1)';
});
window.addEventListener('resize', () => {
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
createParticles();
});
// Control functions
function toggleGravity() {
gravityEnabled = !gravityEnabled;
}
function explodeParticles() {
particles.forEach(particle => {
particle.vx = (Math.random() - 0.5) * 10;
particle.vy = (Math.random() - 0.5) * 10;
});
}
function resetParticles() {
createParticles();
}
// Initialize
createParticles();
animate(0);
</script>
</body>
</html>
This web app creates an interactive particle constellation system with the following features:
-
Dynamic Particle System: Particles move naturally and create connections when near each other, forming beautiful constellations
-
Mouse Interaction:
- Particles are repelled by your cursor when you move it around
- Click and hold to attract particles and create a gravity well
- Custom cursor with smooth following effect
-
Visual Effects:
- Glowing particles with pulsing animation
- Dynamic connections that fade based on distance
- Trail effect from the semi-transparent background clearing
- Smooth color gradients and blend modes
-
Interactive Controls:
- Toggle gravity to watch particles fall and bounce
- Explode button for dramatic particle dispersal
- Reset to restore the initial state
-
Performance Monitoring: Real-time FPS counter and particle count display
The entire visualization runs at 60 FPS with optimized rendering and creates a mesmerizing, interactive experience that responds beautifully to user input. The particles form ever-changing constellations as they move through space, creating a unique visual experience every moment.