For this project, we were to take one image, change the colors of it, then recreate it four times to make an Andy Warhol style collage of ourselves. We were to write the methods that change the colors and also figure out how to make the picture re arrange itself into four smaller versions.
To solve the task, I first wrote four functions that changed the colors of my pixels in different ways. I wrote a method to swap the red and blue pixels, swap the green and blue pixels, swap the green and red pixels, and one to swap them all around. To make these functions, I passed my function a pixmap, looped over all the pixels, and reset the pixels to have swapped color values. Next, in my main function, I wrote code that took in a pixmap from the terminal, then cloned it four times and assigned each clone to its own variable. After doing that, my code used one of my functions on each of the pixmaps to change the colors in the picture. Next, I created a window that was two times the width and height of my picture so that all four pictures could fully fit in my window. After creating the window, I used the putPixmap function to put each of the four different pictures into the window, one in each corner. Finally, I saved the collage so that I could open it with my show method.
I also made a function that changed only the blue screen pixels to be green. To do this, I looped over all the pixels in the pixmap. Then, I used a conditional statement to see if the pixels were very blue. In order for a pixel to be very blue, it had to have a blue value that was greater than the green value and also greater than twice the red value of the pixel. If it passed this condition, I changed the pixel to be completely green. ?
For extensions, I decided to try to change the background color to something more. In doing this, I made a small checker board which created a very interesting color and texture of the background. To do this, I looped over the very blue pixels but this time, I checked to see if it had an even row and col using modulo, and if they were, I made them red and if they were odd I made them green.
From doing this project, I learned how to use the graphics package. I learned how to figure out the r, g, b values and change them to make cool new images. I also learned how to make new windows and title them. Also, I learned how to tell programs to save things that I make using the save() function.