xxxxxxxxxx
58
blobs = [];
function setup() {
createCanvas(400, 400);
frameRate(10);
for (let i = 0; i < 5; i++) {
let r = floor(random(20, 50));
let x = random(r + 1, width - r - 1);
let y = random(r + 1, height - r - 1);
blobs[i] = new Blob(x, y, r);
}
}
function draw() {
background(0);
loadPixels();
getIntensitySum();
threshold();
updatePixels();
for (let b of blobs) {
b.update();
}
}
function getIntensitySum() {
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
for (let b of blobs) {
let index = 4 * (i + j * width);
let d = dist(i, j, b.pos.x, b.pos.y);
let intensity = b.r / d * 100;
pixels[index + 0] += intensity;
pixels[index + 1] += intensity;
pixels[index + 2] += intensity;
}
}
}
}
function threshold() {
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
let index = 4 * (i + j * width);
if (pixels[index] < 200) {
intensity = 0;
} else {
intensity = 255;
}
pixels[index + 0] = intensity / 255 * 100;
pixels[index + 1] = intensity;
pixels[index + 2] = intensity / 255 * 100;
}
}
}