Midterm exam 1 review Sp2005: Posterize
Comments? Questions? Answers? Questions on Answers? Comments on Answers?
public void newPosterize()
{
Pixel pixel = null;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
// loop through the pixels
for (int x = 0; x this.getWidth(); x++) {
for (int y = 0; y this.getHeight(); y++) {
// get the current pixel and colors
pixel = this.getPixel(x,y);
redValue = pixel.getRed();
greenValue = pixel.getGreen();
blueValue = pixel.getBlue();
// check for red range and change color
if (redValue <= 128)
redValue = 5;
else if (redValue > 128)
redValue = 255;
// check for green range
if (greenValue < 10)
greenValue = 200;
else if (greenValue > 200)
greenValue = 10;
// check for blue range
if (blueValue <= 250)
blueValue = 200;
else if (blueValue > 250)
blueValue = 201;
// set the colors
pixel.setRed(redValue);
pixel.setGreen(greenValue);
pixel.setBlue(blueValue);
}
}
}
Student36
when do we use else v. else if?
You don't ever have to use else. If you do, having else if just means that you've got another if after the else. Nothing special. Mark Guzdial |
Link to this Page