please format code with </> button * homework policy * asking questions
PImage foto;
int maxImages = 4; // Img in totale
int imageIndex = 0; // Img iniziale
PImage images = new PImage[maxImages]; // Serie di Img
// images = new PImage {image1, image2, image3};
void setup() {
size(500, 500);
foto=loadImage(“Data/nin1.jpg”);
badwitch(foto.pixels);
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( “nin” + i + “.jpg” );
}
frameRate(1);
}
void draw() {
image(images[imageIndex], 0, 0);
imageIndex = (imageIndex + 1);
saveFrame(“output/file_####.png”);
}
void badwitch(int pixels) {
for (int i=0; i<pixels.length; i++) {
int c=pixels[i];
float b=(c&0xff)/255f;
pixels[i]=color(255*badwitch(b));
}
}
float badwitch(float u) {
float invert=0.5;
float r;
if (u<invert)
r=map(u, 0, invert, 1, 0);
else
r=map(u, invert, 1, 0, 1);
return r;
}
SomeOne
September 6, 2020, 5:13am
2
Next time please format your code. It makes it so much easier to read and it improves chances to be answered.
Your quite close with your code and it needs a few replacement of code lines and a few new lines of code.
PImage foto;
int maxImages = 4; // Img in totale
int imageIndex = 0; // Img iniziale
PImage[] images = new PImage[maxImages]; // Serie di Img
//[] images = new PImage[]{image1, image2, image3};
void setup() {
size(500, 500);
foto=loadImage("Data/nin1.jpg");
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( "nin" + i + ".jpg" );
}
//frameRate(1); //not needed unless you really want to see each image separately for a second
}
void draw() {
for(PImage photo: images) {
photo.loadPixels(); //To get access to pixel array
badwitch(photo.pixels);
photo.updatePixels(); //stores changes made to pixel array
image(photo, 0, 0);
imageIndex = (imageIndex + 1);
saveFrame("output/file_" + imageIndex + ".png");
}
}
void badwitch(int[] pixels) {
for (int i=0; i<pixels.length; i++) {
int c=pixels[i];
float b=(c&0xff)/255f;
pixels[i]=color(255*badwitch(b));
}
}
float badwitch(float u) {
float invert=0.5;
float r;
if (u<invert)
r=map(u, 0, invert, 1, 0);
else
r=map(u, invert, 1, 0, 1);
return r;
}
noel
September 6, 2020, 6:08am
3
I always wonder why so many users have this on the top of their post and then continue with an unformatted code.
Thank you, but, how can I stop at function at the fourth image?
SomeOne
September 6, 2020, 12:14pm
5
Well, it stops at last (fourth) image. If you want to end the program you can add exit()
at the end of draw()
.
for(PImage photo: images) {
is same thing as
for(int i = 0; i < images.length, i++) {
PImage photo = images[i];
Chrisir
September 6, 2020, 5:14pm
6
wondered what badwitch effect is…
Bad Witch is the ninth studio album by American industrial rock band Nine Inch Nails, released by The Null Corporation and Capitol Records on June 22, 2018. It is the last of a trilogy of releases, following their two previous EPs Not The Actual Events (2016) and Add Violence (2017). As with the previous releases in the trilogy, it was produced by frontman Trent Reznor and Atticus Ross, making it the band's first studio album since 2007's Year Zero to not be co-produced by the long-time collabo...
NIN
raron
September 6, 2020, 5:25pm
7
For code you don’t want repeated over and over again, (usually) better to put it in the setup() section. You may want to stopit with exit() or noLoop(). draw() section loops all the time.
EDIT: Partly what @SomeOne also said… (I should read pror posts better)