51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
async function setup() {
|
|
img1 = await new Promise(resolve => loadImage('assets/wallpaper/lagrugru.jpg', resolve));
|
|
createCanvas(img1.width, img1.height);
|
|
background(255, 255, 55)
|
|
// performance enhancmend (from LLM)
|
|
img1.loadPixels();
|
|
for (let y = 0; y < img1.height; y++) {
|
|
for (let x = 0; x < img1.width; x++) {
|
|
let idx = (x + y * img1.width) * 4;
|
|
let r = img1.pixels[idx];
|
|
let g = img1.pixels[idx+1];
|
|
let b = img1.pixels[idx+2];
|
|
let sum = r + g + b;
|
|
let threshold = random(0, 255) * 3;
|
|
set(x, y, sum < threshold ? color(0) : color(255));
|
|
}
|
|
}
|
|
updatePixels();
|
|
|
|
//original code (works to but somettimes not good for bigger images)
|
|
/*
|
|
for (let col = 0; col < img1.width; col += 1) {
|
|
for (let row = 0; row < img1.height; row += 1) {
|
|
let c = img1.get(col, row);
|
|
|
|
if (c[0] + c[1] + c[2] < random(0, 255) * 3) {
|
|
c[0] = 0;
|
|
c[1] = 0;
|
|
c[2] = 0;
|
|
} else {
|
|
c[0] = 255;
|
|
c[1] = 255;
|
|
c[2] = 255;
|
|
}
|
|
stroke(color(c));
|
|
strokeWeight(1);
|
|
point(col, row);
|
|
}
|
|
}
|
|
console.log('finished');
|
|
*/
|
|
}
|
|
|
|
|
|
function draw() {
|
|
|
|
}
|
|
|
|
function mousePressed() {
|
|
|
|
} |