xxxxxxxxxx
76
let img;
let scaleFactor = 0.3;
let blockSize = 9;
let clearRadius = 50;
function preload() {
img = loadImage("skark/5a95ad23b8af9ed82a49f587b308708.jpg");
}
function setup() {
img.resize(img.width * scaleFactor, img.height * scaleFactor);
createCanvas(img.width, img.height);
img.loadPixels();
}
function draw() {
background(255);
let waveAmplitude = 15;
let waveFrequency = 0.02;
for (let y = 0; y < img.height; y += blockSize) {
for (let x = 0; x < img.width; x += blockSize) {
let distanceToMouse = dist(mouseX, mouseY, x, y);
if (distanceToMouse <= clearRadius) {
for (let dy = 0; dy < blockSize; dy++) {
for (let dx = 0; dx < blockSize; dx++) {
let px = x + dx;
let py = y + dy;
if (px < img.width && py < img.height) {
let index = (px + py * img.width) * 4;
let r = img.pixels[index];
let g = img.pixels[index + 1];
let b = img.pixels[index + 2];
let a = img.pixels[index + 3];
fill(r, g, b, a);
noStroke();
rect(px, py, 1, 1);
}
}
}
} else {
let offsetX = sin((y * waveFrequency) + frameCount * 0.05) * waveAmplitude;
let offsetY = sin((x * waveFrequency) + frameCount * 0.05) * waveAmplitude;
let avgR = 0, avgG = 0, avgB = 0, avgA = 0;
let count = 0;
for (let dy = 0; dy < blockSize; dy++) {
for (let dx = 0; dx < blockSize; dx++) {
let px = x + dx;
let py = y + dy;
if (px < img.width && py < img.height) {
let index = (px + py * img.width) * 4;
avgR += img.pixels[index];
avgG += img.pixels[index + 1];
avgB += img.pixels[index + 2];
avgA += img.pixels[index + 3];
count++;
}
}
}
avgR = avgR / count;
avgG = avgG / count;
avgB = avgB / count;
avgA = avgA / count;
fill(avgR, avgG, avgB, avgA);
noStroke();
rect(x + offsetX, y + offsetY, blockSize, blockSize);
}
}
}
}