Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Final exam review Spring2007:Writing methods on the Picture class

Back to Final Review-Spring 2007

Questions? Answers? Comments?


   public void vertical_stripes()
  {
    Pixel[] pixels = this.getPixels();
    Pixel pixel = null;
    int index = 0;
    
    for (int x=0; x<this.getWidth(); x+=5){
      for (int y=0; y<this.getHeight(); y++){
        for (int i=0; i<2; i++){
          if (i == 0){
            pixel = pixels[index];
            pixel.setColor(Color.red);
            index++;
            x=x+5;}
          if (i == 1){
            pixel = pixels[index];
            pixel.setColor(Color.green);
            index++;}        
        }
      }    
    }
  } 
something isn't right about this. it only does one row of pixels. and the spacing is off too. could you give me an idea of what needs to happen?


public void vertical_stripes()
  {
    
    // get the array of pixels from the current picture
    Pixel[] pixels = this.getPixels();
    
    //  declare the variable that will refer to the current pixel
    Pixel pixel = null;
    
    
    for(int i = 0; i < pixels.length; i++){
    
    
    
      // get the current pixel
      pixel = pixels[i];
      
    
      pixel.setBlue(0);
      pixel.setRed(255);
      pixel.setGreen(0);
      
      i = i+3;
    }
    for(int j = 2; j < pixels.length; j++){
   
    
    
      // get the current pixel
      pixel = pixels[j];
      
      
      pixel.setBlue(0);
      pixel.setRed(0);
      pixel.setGreen(255);
      
      j = j+3;
    }
  }
This one worked for me... but i'm worried that it just happened to work because the pic had just the right amount of pixels in its width, is that right?

public void addVert(){ 
Pixel[] pixels = this.getPixels();
Pixel pix = null;
int srcy=0; int srcx=0;
   while (int y < getHeight()){
     while (int x < getWidth()){
       pix= this.getPixel(srcx,srcy); pix.setColor(Color.red);srcx+3;
       pix= this.getPixel(srcx,srcy); pix.setColor(Color.green);srcx+3;
     }srcy++;}this.show;return this;}
This one only does the first line.... please help

public void vertical_stripes()
{
for (int y = 0; y < getHeight(); y++){
   for (int x = 0; x < getWidth(); x+=10){
       this.getPixel(x,y).setColor(Color.red)}
   for (int x = 5; x <getWidth(); x+=10){
       this.getPixel(x,y).setColor(Color.green)}
}|

This worked for me with several pictures!
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;
  }
}|

public void vertical_stripes() {
Pixel [] pixels = this.getPixels();
Pixel temp1 = null;
Pixel temp2 = null;
int r = 5;
int g = 10;
while(r this.getWidth()) {
for(int i =0; ithis.getHeight(); i++){
temp1 = getPixel(r,i);
temp1.setRed(255);
temp1.setBlue(0);
temp1.setGreen(0);
}
r = r + 10;
}
while(g this.getWidth()) {
for(int i =0; ithis.getHeight(); i++){
temp2 = getPixel(g,i);
temp2.setRed(0);
temp2.setBlue(0);
temp2.setGreen(255);
}
g = g + 10;
}


}


}



Link to this Page