Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Abstract Particle Swarm Background #588

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Abstract Particle Swarm Background</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<canvas id="canvas"></canvas>
<script src="script.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

const colors = ['#FF5733', '#FFBD33', '#33FF57', '#33C5FF', '#7A33FF', '#FF33E9', '#FFE233'];

class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = Math.random() * 2 - 1;
this.vy = Math.random() * 2 - 1;
this.size = Math.random() * 3 + 1;
this.color = colors[Math.floor(Math.random() * colors.length)];
}

update() {
this.x += this.vx;
this.y += this.vy;

// Bounce off walls
if (this.x < 0 || this.x > canvas.width) {
this.vx *= -1;
}
if (this.y < 0 || this.y > canvas.height) {
this.vy *= -1;
}
}

draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fillStyle = this.color; // Particle color
ctx.fill();
}
}

// Create particles
const particles = [];
for (let i = 0; i < 100; i++) {
particles.push(new Particle());
}

// Animation loop
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);

particles.forEach(particle => {
particle.update();
particle.draw();
});
}

animate();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body {
margin: 0;
overflow: hidden;
}

canvas {
display: block;
background-color: black;
}
15 changes: 15 additions & 0 deletions assets/html_files/backgrounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,21 @@ <h1>Interactive Squares Background</h1>
</a>
</div>
</div>
<div class="box">
<h1>Abstract Particle Swarm Background</h1>
<div class="preview">
<a href="../../Components/Backgrounds/Abstract-Particle-Swarm-Background/index.html" title="Live Preview"
target="_blank">
<img src="../images/link.png">
</a>
</div>
<div class="source">
<a href="https://github.com/Rakesh9100/Beautiify/tree/main/Components/Backgrounds/Abstract-Particle-Swarm-Background"
title="Source Code" target="_blank">
<img src="../images/github.png">
</a>
</div>
</div>
</div>
</section>

Expand Down
Loading