Just a simplest particle canvas

Developer
Size
2,454 Kb
Views
42,504

How do I make an just a simplest particle canvas?

What is a just a simplest particle canvas? How do you make a just a simplest particle canvas? This script and codes were developed by Godje on 12 September 2022, Monday.

Just a simplest particle canvas Previews

Just a simplest particle canvas - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Just a simplest particle canvas</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> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>

Just a simplest particle canvas - Script Codes CSS Codes

canvas { position: absolute; top: 0; left: 0;
}

Just a simplest particle canvas - Script Codes JS Codes

(function() { var canvasBody = document.getElementById("canvas"), ctx = canvasBody.getContext("2d"), w = canvasBody.width = window.innerWidth, h = canvasBody.height = window.innerHeight, opts = { bgColor: "rgba(200,200,200,alpha)", bgAlpha: 1, particleAmount: 100, particleStyle: "#fcc", particleSize: 2, radius: 50, blinkChance: 0.015 }, particles = [], tick = 0, mPress = false, mPos = { x: w / 2, y: h / 2, } function loop() { window.requestAnimationFrame(loop); ctx.fillStyle = "rgba(0,0,0,0.05)" ctx.fillRect(0, 0, w, h); tick++; //Pushing particles in, they won't be pushed any time, only now... while (opts.particleAmount) { particles.push(new Particle()); opts.particleAmount-- } //Calling every particle to blink and/or update particles.map(function(Particle) { Particle.update(); Particle.blink(); }); }; //The constructor of the particle. It stores all the functions and coords for the particles object function Particle() { this.x = 0; this.y = 0; this.style = opts.particleStyle; //The update function of the particle will update its position this.update = function() { var randomX = mPos.x - (Math.random() * (opts.radius * 2) - opts.radius), randomY = mPos.y - (Math.random() * (opts.radius * 2) - opts.radius); this.x = randomX; this.y = randomY; }; //And then the blink function makes those particles blink. this.blink = function() { var chance = Math.random(); if (chance < opts.blinkChance) { ctx.fillStyle = this.style; ctx.fillRect(this.x, this.y, opts.particleSize, opts.particleSize); } } }; //Calling the loop function to start the whole thing. Then, the loop will call itself by window.requestAnimationFrame loop(); //On mouseDown window.addEventListener("mousedown", function() { mPress = true; }); //On mouseUp window.addEventListener("mouseup", function() { mPress = false; }); //On mouseMove window.addEventListener("mousemove", function(e) { mPos.x = e.pageX; mPos.y = e.pageY; }) //On resize window.addEventListener("resize", function() { w = canvasBody.width = window.innerWidth; h = canvasBody.height = window.innerHeight; //centering the mouse position mouseP = { x: w / 2, y: h / 2 } });
})();
Just a simplest particle canvas - Script Codes
Just a simplest particle canvas - Script Codes
Home Page Home
Developer Godje
Username Godje
Uploaded September 12, 2022
Rating 4
Size 2,454 Kb
Views 42,504
Do you need developer help for Just a simplest particle canvas?

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!

Godje (Godje) Script Codes
Create amazing sales emails 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!