Skip to main content

Section 18.6 Changing Step 3: Changing which data we use

Below is a selection of images that you can use in the programs in this section.
We can also change which part of the picture we read and manipulate. When we are changing several colors at once we can create a new pixel with the desired color using Pixl(red,green,blue) as shown below on line 20.
Data: vangogh.jpg
Figure 18.6.1. Figure: A picture of a man and woman dancing cheek to cheek from Vincent van Gogh
What happens if we skip every other x and y as we manipulate the colors? Maybe make the green 255 and the blue 0?
Let’s try side-to-side copying.

Activity 18.6.2.

Try it: How would you mirror the image from left-to-right around a vertical line in the middle of the picture? Try changing line 22 to these. If you get it right it will look like the women is nose to nose with herself.
  • img.setPixel(halfway - x, y, newPixel)
  • It does mirror, but only the left half
  • img.setPixel(x - halfway, y, newPixel)
  • This creates two copies of the left half
  • img.setPixel(img.getWidth() - 1 - x, y, newPixel)
  • Yes, it looks like the woman is kissing herself
  • img.setPixel(x - img.getWidth(), y, newPixel)
  • No, no effect.
Figure 18.6.3.

Activity 18.6.4.

Solution.
You have attempted of activities on this page.