I'll create a particle physics game for you! Here's a complete HTML file with a particle system inside a circular boundary:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Particle Physics Game</title>
<style>
body {
margin: 0;
padding: 20px;
background: #1a1a2e;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: Arial, sans-serif;
}
canvas {
border: 2px solid #16213e;
border-radius: 50%;
background: radial-gradient(circle, #0f3460, #16213e);
box-shadow: 0 0 30px rgba(15, 52, 96, 0.5);
}
.controls {
position: absolute;
top: 20px;
left: 20px;
color: white;
font-size: 14px;
}
</style>
</head>
<body>
<div class="controls">
<div>Particles: <span id="particleCount">0</span></div>
<div>Click to add particles manually</div>
</div>
<canvas id="gameCanvas" width="600" height="600"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const particleCountElement = document.getElementById('particleCount');
// Game settings
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const boundaryRadius = 280;
const gravity = 0.1;
const friction = 0.99;
const bounce = 0.8;
// Particle types
const shapes = ['circle', 'square', 'triangle'];
const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const colors = ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57', '#ff9ff3', '#54a0ff', '#5f27cd'];
let particles = [];
class Particle {
constructor(x, y) {
this.x = x || centerX + (Math.random() - 0.5) * 100;
this.y = y || centerY + (Math.random() - 0.5) * 100;
this.vx = (Math.random() - 0.5) * 8;
this.vy = (Math.random() - 0.5) * 8;
this.size = Math.random() * 15 + 10;
this.color = colors[Math.floor(Math.random() * colors.length)];
this.rotation = 0;
this.rotationSpeed = (Math.random() - 0.5) * 0.2;
// Random type
const typeRandom = Math.random();
if (typeRandom < 0.33) {
this.type = 'shape';
this.shape = shapes[Math.floor(Math.random() * shapes.length)];
} else if (typeRandom < 0.66) {
this.type = 'character';
this.character = characters[Math.floor(Math.random() * characters.length)];
} else {
this.type = 'number';
this.character = numbers[Math.floor(Math.random() * numbers.length)];
}
}
update() {
// Apply gravity
this.vy += gravity;
// Apply velocity
this.x += this.vx;
this.y += this.vy;
// Apply friction
this.vx *= friction;
this.vy *= friction;
// Update rotation
this.rotation += this.rotationSpeed;
// Check boundary collision
const distanceFromCenter = Math.sqrt(
Math.pow(this.x - centerX, 2) + Math.pow(this.y - centerY, 2)
);
if (distanceFromCenter + this.size/2 > boundaryRadius) {
// Calculate collision normal
const angle = Math.atan2(this.y - centerY, this.x - centerX);
// Position particle just inside boundary
this.x = centerX + Math.cos(angle) * (boundaryRadius - this.size/2);
this.y = centerY + Math.sin(angle) * (boundaryRadius - this.size/2);
// Reflect velocity
const normalX = Math.cos(angle);
const normalY = Math.sin(angle);
const dotProduct = this.vx * normalX + this.vy * normalY;
this.vx = (this.vx - 2 * dotProduct * normalX) * bounce;
this.vy = (this.vy - 2 * dotProduct * normalY) * bounce;
// Add some random bounce variation
this.vx += (Math.random() - 0.5) * 2;
this.vy += (Math.random() - 0.5) * 2;
}
}
draw() {
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.rotation);
ctx.fillStyle = this.color;
ctx.strokeStyle = this.color;
ctx.lineWidth = 2;
if (this.type === 'shape') {
switch (this.shape) {
case 'circle':
ctx.beginPath();
ctx.arc(0, 0, this.size/2, 0, Math.PI * 2);
ctx.fill();
break;
case 'square':
ctx.fillRect(-this.size/2, -this.size/2, this.size, this.size);
break;
case 'triangle':
ctx.beginPath();
ctx.moveTo(0, -this.size/2);
ctx.lineTo(-this.size/2, this.size/2);
ctx.lineTo(this.size/2, this.size/2);
ctx.closePath();
ctx.fill();
break;
}
} else {
// Draw character or number
ctx.font = `bold ${this.size}px Arial`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(this.character, 0, 0);
}
ctx.restore();
}
}
function addParticle(x, y) {
particles.push(new Particle(x, y));
updateParticleCount();
}
function updateParticleCount() {
particleCountElement.textContent = particles.length;
}
function drawBoundary() {
ctx.strokeStyle = '#4ecdc4';
ctx.lineWidth = 3;
ctx.setLineDash([10, 5]);
ctx.beginPath();
ctx.arc(centerX, centerY, boundaryRadius, 0, Math.PI * 2);
ctx.stroke();
ctx.setLineDash([]);
}
function gameLoop() {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw boundary
drawBoundary();
// Update and draw particles
particles.forEach(particle => {
particle.update();
particle.draw();
});
requestAnimationFrame(gameLoop);
}
// Add particle every second
setInterval(() => {
addParticle();
}, 1000);
// Click to add particles
canvas.addEventListener('click', (e) => {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Check if click is inside boundary
const distanceFromCenter = Math.sqrt(
Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2)
);
if (distanceFromCenter < boundaryRadius - 20) {
addParticle(x, y);
}
});
// Start with a few particles
for (let i = 0; i < 3; i++) {
addParticle();
}
// Start game loop
gameLoop();
</script>
</body>
</html>
This particle game includes:
Physics Features:
- Gravity pulls particles downward
- Realistic bouncing off the circular boundary
- Friction that gradually slows particles down
- Collision detection with the circular walls
Particle Variety:
- Geometric shapes (circles, squares, triangles)
- Random alphabet letters (A-Z)
- Numbers (0-9)
- Random colors and sizes
- Rotation animation
Interactive Elements:
- New particle spawns automatically every second
- Click inside the circle to manually add particles
- Particle counter in the top-left
- Particles bounce with slight randomness for natural movement
Visual Polish:
- Gradient background
- Glowing boundary circle
- Smooth animations
- Responsive design
The particles will bounce around realistically inside the circular boundary, and you can click anywhere inside the circle to add more particles instantly. Each particle has its own physics properties and will interact naturally with the circular walls!