Particle Emitter

Developer
Size
2,320 Kb
Views
6,072

How do I make an particle emitter?

What is a particle emitter? How do you make a particle emitter? This script and codes were developed by Lloydwheeler on 26 January 2023, Thursday.

Particle Emitter Previews

Particle Emitter - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Particle Emitter</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Particle Emitter - Script Codes CSS Codes

body { background: #333; height: 100%; margin: 0; overflow: hidden;
}
#canvas { background: #222; border-bottom: 1px solid #444;
}

Particle Emitter - Script Codes JS Codes

/* Horrible JS! Quickly hacked together so ignore the bad practices */
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
canvas.width = $(window).width();
canvas.height = $(window).height();
var particles = [];
var emissionPoint = {x: canvas.width/2, y: canvas.height/2};
var mouse = {x: 0, y: 0};
var mouseDelta = {x: 0, y: 0};
var gravity = 0.25;
function Particle(x, y, size, vx, vy, decayRate) { this.position = {x: x, y: y}; this.size = size; this.velocity = {x: vx, y: vy}; this.decayRate = decayRate;
}
$('#canvas').click(function(e) { emissionPoint.x = e.clientX; emissionPoint.y = e.clientY;
});
setInterval(function() { ctx.clearRect(0,0,canvas.width,canvas.height); particles.push(new Particle(emissionPoint.x, emissionPoint.y, Math.random()*10, randomRange(-10,10), randomRange(-5,5), Math.random())); for(var i = 0; i < particles.length; i++) { ctx.fillStyle = "rgba(0,255,255," + particles[i].decayRate + ")"; ctx.fillRect(particles[i].position.x, particles[i].position.y, particles[i].size, particles[i].size); particles[i].position.x += particles[i].velocity.x; particles[i].position.y += particles[i].velocity.y; particles[i].velocity.x *= .98; particles[i].velocity.y *= .98; particles[i].velocity.y += gravity; particles[i].decayRate -= Math.random()*.01; if (particles[i].position.x > canvas.width || particles[i].position.x < 0) { particles[i].velocity.x *= -1; } if (particles[i].position.y > canvas.height || particles[i].position.y + particles[i].size < 0) { particles[i].velocity.y *= -.75; } if(particles[i].decayRate <= 0) { particles.splice(i, 1); } }
}, 16);
function randomRange(min, max) { if (min < 0) { return min + Math.random() * (Math.abs(min)+max); }else { return min + Math.random() * max; }
}
Particle Emitter - Script Codes
Particle Emitter - Script Codes
Home Page Home
Developer Lloydwheeler
Username lloydwheeler
Uploaded January 26, 2023
Rating 3
Size 2,320 Kb
Views 6,072
Do you need developer help for Particle Emitter?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Lloydwheeler (lloydwheeler) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!