Final exam review Fall2007:Writing methods on the Picture class
Help your fellow students here!
Back to Final Review-Fall 2007
public void vertical_stripes()
{
int counter = 0;
// loop through the columns
for (int x = 0; x < getWidth(); x+=2)
{
// loop through the rows
for (int y=0; y < getHeight(); y++)
{
// set the pixel to cprrect color
if(counter % 2 == 0)
this.getPixel(x,y).setColor(Color.red);
else
this.getPixel(x,y).setColor(Color.green);
}
counter++;
}
}
Mine is different, but it worked for me:
public void vertical_stripes(){
int stripe = 0;
Pixel pixelA;
Pixel pixelB;
for (int y=0; y this.getHeight(); y++){
pixelA = this.getPixel(stripe, y);
pixelA.setRed(255); pixelA.setBlue(0); pixelA.setGreen(0);
pixelB = this.getPixel((stripe+2),y);
pixelB.setRed(0); pixelB.setBlue(0); pixelB.setGreen(255);
stripe = stripe + 4;
}
}
Link to this Page