Alternated boxes with for loop
in
Programming Questions
•
2 years ago
Hello everyone,
i have this code which doesn't work. I want a checkerboard effect. This is my exercise:
1) In the "invertColors" I need to take a picture, cut it, and invert the colors with filter (INVERT).
2) In the "checkerboard" I need to take the cutted picture of the output of "invertColors" and I want to achieve the checkerboard effect with 9 boxes using "invertColors" in alternated boxes (like a checkerboard).
How to do this changing this code?
PImage img1, img2;
void setup() {
size (145,125);
}
void draw() {
invertColors();
chessboard();
}
void invertColors(){
size(145, 125);
img1 = loadImage("http://www.fidomicio.provincia.ancona.it/Immagini/foto_cane1_imagelarge.jpg");
img2 = img1.get(90, 10, 145, 125);
image(img2, 0, 0);
filter(INVERT);
}
void chessboard(){
for (int i=0; i<9; i++) {
image(img2.get((width/3)*(i%3), (height/3)*(i/3), width/3, height/3), (width/3)*(i%3), (height/3)*(i/3));
if (i%2==0){
invertColors();
}
}
}
i have this code which doesn't work. I want a checkerboard effect. This is my exercise:
1) In the "invertColors" I need to take a picture, cut it, and invert the colors with filter (INVERT).
2) In the "checkerboard" I need to take the cutted picture of the output of "invertColors" and I want to achieve the checkerboard effect with 9 boxes using "invertColors" in alternated boxes (like a checkerboard).
How to do this changing this code?
PImage img1, img2;
void setup() {
size (145,125);
}
void draw() {
invertColors();
chessboard();
}
void invertColors(){
size(145, 125);
img1 = loadImage("http://www.fidomicio.provincia.ancona.it/Immagini/foto_cane1_imagelarge.jpg");
img2 = img1.get(90, 10, 145, 125);
image(img2, 0, 0);
filter(INVERT);
}
void chessboard(){
for (int i=0; i<9; i++) {
image(img2.get((width/3)*(i%3), (height/3)*(i/3), width/3, height/3), (width/3)*(i%3), (height/3)*(i/3));
if (i%2==0){
invertColors();
}
}
}
1