PImage updatePixels feedback
in
Core Library Questions
•
1 year ago
I am new to the PImage class, following Daniel Shiffman's Learning Processing PDF.
I am trying to make a sketch where the image pixels are changed according to their neighbours and then updated, then changed again etc. iteratively/cellular automata.
In the sketch below, I load the pixels from the image, go through each one and compare it to it's left neighbour, then say that if the one on the left is less than the current pixel, increase it's brightness.
I think my problem is that when I say updatePixels(), it is not storing this change, it is just displaying it, so when I call loadPixels() it is loading the pixels from the original image again rather than the newly modified one.
Do I need to load the pixels into a 2D array in order to do what I want? what is the simplest way to achieve this kind of feedback effect?
This is the sketch I have made:
PImage img;
void setup() {
size (500, 500);
img = loadImage("pix/12in.jpg");
}
void draw() {
loadPixels();
for (int y = 0; y < img.height; y ++) {
for (int x = 1; x < img.width; x ++) {
int loc = x+ y*img.width;
int locLeft =(x-1)+ y*img.width ;
float gr = brightness(img.pixels[loc]);
if (brightness(img.pixels[loc]) < brightness(img.pixels[locLeft])){
gr ++;
}
pixels[loc] = color(gr);
}
}
updatePixels();
}
1