Change Contents of the Bubble
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Methods to turn George Best into a Northern Ireland International

Add this code to the Picture class. Note that there are two public methods: the void method demonstrated in class that changes the original picture and a corresponding Picture method that returns an Irish-jerseyed version of the original.
  /*
   * georgeBestEffect -- REMOVEDge a rectangle within picture (e.g. football jersey)
   * from Manchester United red to Northern Ireland green.
   */
  public void georgeBestEffect(int left, int right, int top, int bottom, double threshold) {
    for (int x = left; x < this.getWidth() && x < right; x++) {
      for (int y = top; y < this.getHeight() && y < bottom; y++) {
        // Make the red pixels in this area corresponding shade of green.
        Pixel pix = this.getPixel(x, y);
        if (!this.isGreenAlready(pix, threshold)) {
          pix.setColor(irishColor(pix));
        }
      }
    }
  }
  
  // Is the pixel green already (e.g. grass, white shorts)? 
  private boolean isGreenAlready(Pixel pixel, double limit) {
    return (pixel.getGreen() > limit);
  }
  
  // The corresponding Northern Ireland color to the color of a pixel
  private java.awt.Color irishColor(Pixel pixel) {
    int redVal = pixel.getGreen();
    int greenVal = (int) (pixel.getRed() * 0.7);
    int blueVal = pixel.getBlue();
    return new java.awt.Color(redVal, greenVal, blueVal);    
  }
  
  /*
   * Return a new picture that is a George Best effect of this picture.
   * Left, right, top, and bottom are the rectangle bounds for the effect.
   * Threshold determines what intensity of green in the pixels is ignored.
   */
  public Picture makeGeorgeBestEffect(int left, int right, int top, int bottom, double threshold) {
    Picture gbPic = new Picture(this.getWidth(), this.getHeight());
    gbPic.copyPicture(this);
    gbPic.georgeBestEffect(left, right, top, bottom, threshold);
    return gbPic;
  }


Link to this Page