Brownian Gnats

Size
2,822 Kb
Views
74,888

How do I make an brownian gnats?

Click canvas to reset.I'm exploring Brownian Motion. Here I combined it with the concept of particle trails, as explained by David Shiffman on Coding Train. Instead of drawing dots on the trail, I draw lines from the current position to all the points in the trail.. What is a brownian gnats? How do you make a brownian gnats? This script and codes were developed by Johan Karlsson on 24 July 2022, Sunday.

Brownian Gnats Previews

Brownian Gnats - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Brownian Gnats</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.6/p5.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Brownian Gnats - Script Codes CSS Codes

html, body { margin: 0;
}
canvas { display: block;
}

Brownian Gnats - Script Codes JS Codes

"use strict";
/* Johan Karlsson (DonKarlssonSan) Click canvas to reset.
*/
function Particle() { this.pos = createVector(random(windowWidth), random(windowHeight)); this.tail = []; this.tailLength = 7;
}
Particle.prototype.move = function () { if (this.tail.length > this.tailLength) { this.tail.splice(0, 1); } this.tail.push(this.pos.copy()); this.pos.x += random(-particleStepMax, particleStepMax); this.pos.y += random(-particleStepMax, particleStepMax);
};
Particle.prototype.draw = function () { var _this = this; this.tail.forEach(function (pos) { line(_this.pos.x, _this.pos.y, pos.x, pos.y); });
};
var particles;
var particleStepMax;
function setup() { cursor(HAND); particleStepMax = 6; initParticles(); createCanvas(windowWidth, windowHeight);
}
function draw() { background(255); particles.forEach(function (p) { p.move(); p.draw(); });
}
function initParticles() { particles = []; for (var i = 0; i < 40; i++) { particles.push(new Particle()); }
}
function windowResized() { resizeCanvas(windowWidth, windowHeight);
}
function mouseClicked() { initParticles(); background(255);
}
Brownian Gnats - Script Codes
Brownian Gnats - Script Codes
Home Page Home
Developer Johan Karlsson
Username DonKarlssonSan
Uploaded July 24, 2022
Rating 4.5
Size 2,822 Kb
Views 74,888
Do you need developer help for Brownian Gnats?

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!

Johan Karlsson (DonKarlssonSan) Script Codes
Create amazing web content 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!