make image noise load better

This commit is contained in:
Jürg Hallenbarter
2026-06-03 11:46:22 +02:00
parent 3084d9de5e
commit 6978b64231
2 changed files with 32 additions and 33 deletions

View File

@@ -66,7 +66,7 @@
<div class="liberayDiv"> <div class="liberayDiv">
<h2>Images manipulation</h2> <h2>Images manipulation</h2>
<div class="liberay"> <div class="liberay">
<iframe src="http://127.0.0.1:5501/liberay.html?sketches=2images.js,image.js,imageNoice.js,L-System.js&size=200" frameborder="0"></iframe> <iframe src="http://127.0.0.1:5501/liberay.html?sketches=imageOverlap,2images.js,image.js,imageNoice.js,L-System.js&size=200" frameborder="0"></iframe>
</div> </div>
</div> </div>

View File

@@ -1,27 +1,28 @@
async function setup() { let img1;
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) let processing = true;
/* let currentRow = 0;
for (let col = 0; col < img1.width; col += 1) { let currentCol = 0;
for (let row = 0; row < img1.height; row += 1) {
let c = img1.get(col, row); async function setup() {
img1 = await new Promise(resolve => loadImage('assets/wallpaper/Bird_Pixel_art_1.png', resolve));
createCanvas(img1.width, img1.height);
background(255, 255, 255)
}
function draw() {
if (!processing){
return;
}
let imgWidth = img1.width;
let imgHeight = img1.height;
if (currentRow < imgHeight) {
for (let col = 0; col < imgWidth; col++) {
let c = img1.get(col, currentRow);
if (c[0] + c[1] + c[2] < random(0, 255) * 3) { if (c[0] + c[1] + c[2] < random(0, 255) * 3) {
c[0] = 0; c[0] = 0;
@@ -32,18 +33,16 @@ async function setup() {
c[1] = 255; c[1] = 255;
c[2] = 255; c[2] = 255;
} }
stroke(color(c)); stroke(color(c));
strokeWeight(1); strokeWeight(2);
point(col, row); point(col, currentRow);
}
} }
currentRow++;
} else {
processing = false;
console.log('finished'); console.log('finished');
*/ }
}
function draw() {
} }
function mousePressed() { function mousePressed() {