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

PreQuiz 1 - Spring 2006

Below is the sunset method that we wrote in class last week:

     
/**
   * Method to make a picture look sunset-like
   */
  public void sunsetize()
  {
    
    // 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;
    
    // declare the index and initialize it to 0
    int index = 0;
    
    // loop through all the pixels
    while (index < pixels.length)
    {
      // get the current pixel
      pixel = pixels[index];
      
      // decrease the green and blue by 20%
      pixel.setGreen(
               (int)
                    (pixel.getGreen()*0.8));
      pixel.setBlue(
               (int)
                    (pixel.getBlue()*0.8));
      
      index++;
    }
  }


Recall that creating a grayscale version of a picture is done by setting the red, green, and blue all to the same value. A good value to use is the average of the red, green, and blue pixel values.


Questions? Answers? Comments?





Link to this Page