Damn Particlez

Developer
Size
2,805 Kb
Views
14,168

How do I make an damn particlez?

Playing with particles. move the mouse and click. What is a damn particlez? How do you make a damn particlez? This script and codes were developed by Moklick on 20 November 2022, Sunday.

Damn Particlez Previews

Damn Particlez - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Damn Particlez</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <span class="info">CLICK!</span>
<canvas id="app"></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>

Damn Particlez - Script Codes CSS Codes

html, body { margin: 0; padding: 0; overflow: hidden; background-color: #000; color:#efe;
}
.info{ position:absolute; width:200px; text-align:center; left:50%; margin:5px 0 0 -100px; font-weight:bold;
}

Damn Particlez - Script Codes JS Codes

window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); }; })();
var RandomGen = { randomize : function(a, b) { return Math.random() * (b - a) + a; }, randomInt : function(a, b) { return Math.floor(Math.random() * (b - a) + a); }, getDirVec : function(x,y){ var angle = this.randomize(0,(2 * Math.PI)); return new Vector(Math.sin(angle) * x, - Math.cos(angle) * y); },
}
var Vector = function(x,y){ this.x = x || 0; this.y = y || 0; this.add = function(v){ this.x += v.x; this.y += v.y; return this; }; this.mult = function(v){ this.x *= v.x; this.y *= v.y; };
}
var App = { init : function(){ this.canvas = document.getElementById('app'); this.context = this.canvas.getContext('2d'); this.particles = []; this.WIDTH = window.innerWidth; this.HEIGHT = window.innerHeight; this.canvas.width = this.WIDTH; this.canvas.height = this.HEIGHT; this.bindHandlers(); this.draw(); }, bindHandlers : function(){ this.canvas.addEventListener( 'click', this.fireParticles,false); this.canvas.addEventListener( 'mousemove', this.fireSmallParticles,false); this.createParticles(this.WIDTH / 2, this.HEIGHT / 2, false); window.onresize = App.resize; }, fireParticles : function(e){ var xPos = e.pageX; var yPos = e.pageY; App.createParticles(xPos,yPos,false); }, fireSmallParticles : function(e){ var xPos = e.pageX; var yPos = e.pageY; App.createParticles(xPos,yPos,true); }, createParticles : function(x,y,isSmall){ var amount = isSmall ? RandomGen.randomInt(10,25) : RandomGen.randomInt(150,350); for (var i = 0; i < amount; i++){ var particle = new Particle(x,y,isSmall); this.particles.push(particle); } }, draw : function(){ for (var i = 0; i < App.particles.length; i++){ App.particles[i].update(); if(App.particles[i].lifetime < 0){ App.particles.splice(i,1); } } App.context.fillStyle = "rgba(0,0,0,0.25)"; App.context.fillRect(0, 0, App.canvas.width, App.canvas.height); window.requestAnimFrame(App.draw); }, resize : function(){ App.canvas.width = window.innerWidth; App.canvas.height = window.innerHeight; }
}
var Particle = function(x,y,isSmall){ this.pos = new Vector(x,y); this.size = isSmall ? RandomGen.randomize(1,1) : RandomGen.randomize(1,8); var acc = RandomGen.randomize(0,this.size); this.dir = RandomGen.getDirVec(acc,acc); this.lifetime = RandomGen.randomize(20,60);
} Particle.prototype.draw = function(){ App.context.fillStyle = "#fff"; App.context.beginPath(); App.context.rect( this.pos.x,this.pos.y,this.size,this.size); App.context.closePath(); App.context.stroke(); App.context.fill(); }; Particle.prototype.update = function(){ this.lifetime--; this.dir.mult(new Vector(.97,.97)); this.pos.add(this.dir); this.draw(); }
App.init();
Damn Particlez - Script Codes
Damn Particlez - Script Codes
Home Page Home
Developer Moklick
Username moklick
Uploaded November 20, 2022
Rating 4
Size 2,805 Kb
Views 14,168
Do you need developer help for Damn Particlez?

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!

Moklick (moklick) 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!