Portrait by Brownian Motion
How do I make an portrait by brownian motion?
When I did my previous Brownian Motion Pen, Text by Brownian Motion , I was already thinking about doing it with an image. And here it is!. What is a portrait by brownian motion? How do you make a portrait by brownian motion? This script and codes were developed by Johan Karlsson on 24 July 2022, Sunday.
Portrait by Brownian Motion - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Portrait by Brownian Motion</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>
Portrait by Brownian Motion - Script Codes CSS Codes
html, body { margin: 0;
}
canvas { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: block;
}
Portrait by Brownian Motion - Script Codes JS Codes
"use strict";
/* Johan Karlsson (DonKarlssonSan) I tried to find the copyright info for the image but failed, the image is all over internet.
*/
function Particle() { this.x = random(w); this.y = random(h); this.oldX = this.x; this.oldY = this.y;
}
Particle.prototype.move = function (stepSize) { this.oldX = this.x; this.oldY = this.y; this.x += random(-stepSize, stepSize); this.y += random(-stepSize, stepSize); if (this.x < 0) this.x = 0; if (this.x > w) this.x = w; if (this.y < 0) this.y = 0; if (this.y > h) this.y = h;
};
Particle.prototype.draw = function () { line(this.oldX, this.oldY, this.x, this.y);
};
var particles;
var iterations;
var theImage;
var px;
var w;
var h;
function preload() { theImage = loadImage("https://s3-us-west-2.amazonaws.com/s.cdpn.io/254249/barack-obama-portrait.jpg");
}
function setup() { cursor(HAND); iterations = 50; w = theImage.width; h = theImage.height; createCanvas(w, h); reset(); stroke(0, 10);
}
function draw() { for (var i = 0; i < iterations; i++) { particles.forEach(function (p) { var x = floor(p.x); var y = floor(p.y); var off = (y * w + x) * 4; var m = (px[off] + px[off + 1] + px[off + 2]) / 3; var stepSize = map(m, 0, 255, 3, 30); p.move(stepSize); p.draw(); }); }
}
function initParticles() { particles = []; for (var i = 0; i < 100; i++) { particles.push(new Particle()); }
}
function initImage() { image(theImage, 0, 0); var img = get(0, 0, w, h); img.loadPixels(); px = img.pixels; background(255);
}
function reset() { initParticles(); clear(); initImage();
}
function mouseClicked() { reset();
}
Developer | Johan Karlsson |
Username | DonKarlssonSan |
Uploaded | July 24, 2022 |
Rating | 3 |
Size | 3,612 Kb |
Views | 76,912 |
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 |
Sine Perlin | 5,654 Kb |
Cash by Brownian Motion | 3,530 Kb |
Apply Filter Effects to Music | 4,027 Kb |
Wayward Walker Worms | 3,123 Kb |
Phone Case Pattern Animation | 2,774 Kb |
Lissajous x Lissajous | 3,369 Kb |
In Tribute to Simon Plouffe | 2,376 Kb |
Brownian Motion | 2,549 Kb |
Circle Fractal | 2,482 Kb |
Rainbow 6-fold Pentille | 4,311 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 |
React Markdown Previewer | C0d0er | 3,190 Kb |
Clock with full screen background | Owebboy | 2,415 Kb |
Firefox Breakout Guide | Quincysoeliman | 2,576 Kb |
A Pen by Patrick Cox | Pcridesagain | 2,899 Kb |
Scoreboard.js basic usage | Tbleckert | 1,733 Kb |
Typefaces with descriptions | Megandoty | 2,944 Kb |
CSS Variables | Jdsteinbach | 4,759 Kb |
Shape Outside - Polygon | Stacy | 3,954 Kb |
Mega menu | DimaZubkov | 5,066 Kb |
A Pen by Anoop | Anoopjohn | 330,760 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!