Name:______________________________________
Read Chapter 5 up to and including Section 5.1 in your book. Pages 131-142.
Answer the following questions:
String word1 = "Loops are"; String word2 = "really"; int value = 1332; System.out.println(word1); for (int i = 0; i < 5; i++) { System.out.println(word2); value++; } System.out.println(value);
Picture
class does:
public void mystery() { for (int x = 0; x < this.getWidth()/2; x++) { for (int y = 0; y < this.getHeight()/2; y++) { this.getPixel(x,y).setColor(Color.black); } } }
Hint: cut and paste this into your Picture class and call it from main on an example picture.
mirrorVertical
from page 135-136 of your text. Make sure you understand what it does and
how it does it. Hint: cut and paste it into the Picture class and call it
from the main class using an example picture.
public void mirrorVertical() { int width = this.getWidth(); int mirrorPoint = width/2; for (int y = 0; y < this.getHeight(); y++) { for (int x = 0; x < mirrorPoint; x++) { Pixel leftPixel = this.getPixel(x,y); Pixel rightPixel = this.getPixel(width - 1 - x, y); rightPixel.setColor(leftPixel.getColor()); } } }
Modify this function so that the top 10 rows, bottom 10 rows, and left and right 10 columns of pixels are left unmirrored. This will create a frame of unmirrored pixels around the final image.
When working on this problem, try to make one modification at a time. For example, first try to modify the function so only the top 10 rows of pixels are unmodified, then try to work on the bottom 10, and so on.
Turn in a printout of your modified method.