Just a simplest particle canvas
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 - 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 } });
})();
Developer | Godje |
Username | Godje |
Uploaded | September 12, 2022 |
Rating | 4 |
Size | 2,454 Kb |
Views | 42,504 |
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!
Name | Size |
Dot Digit Input | 4,156 Kb |
Wavy thing | 3,246 Kb |
A Pen by Godje | 2,209 Kb |
Shoal of Pursuers | 4,099 Kb |
Fancy Background shapes | 2,920 Kb |
Dark Spirit Fire | 3,792 Kb |
FIRE | 3,636 Kb |
Ceasar Cipher Encryptor | 3,793 Kb |
Almost MKBHD animation | 2,802 Kb |
Nice multipart image slider | 4,041 Kb |
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!
Name | Username | Size |
Prism | Pyrografix | 2,843 Kb |
Pure CSS Tooltip | APinix | 2,815 Kb |
CSS Parent Selector | Tomhodgins | 2,143 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
Parallax scrolling scene | Iharosi | 2,485 Kb |
Blog | Rottingroom | 1,430 Kb |
A Pen by Jay | Jaycode | 3,784 Kb |
About Us | Francescaedits | 1,902 Kb |
12 DAYS OF XMAS | Proto78 | 2,313 Kb |
Scarlett Johansson Tribute Page | Diomed | 3,233 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!