
let img;
let gridCols = 80;
let gridRows = 80;
let cellW, cellH;
let levels = [];
let imgReady = false;
let offsetX, offsetY;
let points = [];
function setup() {
createCanvas(1000, 1000);
background(0);
noStroke();
loadImage("../../assets/sticker_lara_006.png", (loadedImg) => {
img = loadedImg;
if (img.width > img.height) {
img.resize(1000, 0);
} else {
img.resize(0, 1000);
}
offsetX = (width - img.width) / 2;
offsetY = (height - img.height) / 2;
cellW = img.width / gridCols;
cellH = img.height / gridRows;
img.loadPixels();
for (let y = 0; y < gridRows; y++) {
levels[y] = [];
for (let x = 0; x < gridCols; x++) {
let px = int(x * cellW);
let py = int(y * cellH);
let idx = (py * img.width + px) * 4;
let r = img.pixels[idx];
let g = img.pixels[idx + 1];
let b = img.pixels[idx + 2];
let brightness = (r + g + b) / 3;
let level = map(brightness, 0, 255, 2, 5);
levels[y][x] = level;
let cx = offsetX + x * cellW + cellW / 2;
let cy = offsetY + y * cellH + cellH / 2;
points.push({
x: cx,
y: cy,
ox: cx,
oy: cy,
vx: 0,
vy: 0,
baseSize: level,
});
}
}
imgReady = true;
});
}
function draw() {
background(0);
if (!imgReady) return;
for (let p of points) {
let d = dist(mouseX, mouseY, p.x, p.y);
let size = p.baseSize;
if (d < 150) {
let influence = exp(-pow(d, 2) / (2 * pow(50, 2)));
size = lerp(p.baseSize, 10, influence);
let angle = atan2(p.y - mouseY, p.x - mouseX);
let force = (150 - d) * 0.01;
p.vx += cos(angle) * force;
p.vy += sin(angle) * force;
}
let dx = p.ox - p.x;
let dy = p.oy - p.y;
p.vx += dx * 0.1;
p.vy += dy * 0.1;
p.vx *= 0.9;
p.vy *= 0.9;
p.x += p.vx;
p.y += p.vy;
fill(200, 190, 55);
ellipse(p.x, p.y, size, size);
}
}