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

Midterm exam 1 review Fall2005: Flip the other way

Back to Midterm Exam 1 Review Fall2005

Questions? Answers? Comments?



chage the first for loop to this, and you're golden. we did this one in recitation.
for (int srcx = getWidth()-1, trgx= 0; srcx >= 0; srcx–, trgx++);

Removed at KS request

Anyone want to try writing the code to flip horizontally, top and/or bottom? It's always good to cover the bases...
Student159

//*Flip horizontally, top.

  public Picture fliphor() {
    
    Pixel currPixel;
    Picture target = new Picture((int) this.getWidth(),this.getHeight());
    for (int srcx = 0, trgx = 0; srcx < getWidth(); srcx++, trgx++)
    {
      for (int srcy = 0, trgy = getHeight()-1; srcy < getHeight(); srcy++, trgy--)
      {
        currPixel = this.getPixel(srcx,srcy);
        target.getPixel(trgx,trgy).setColor(currPixel.getColor());
      }
    };
    return target;
  }

//*Flip horizontally, bottom.  
  public Picture fliphor2() {
    Pixel currPixel;
    Picture target = Picture target = new Picture((int) this.getWidth(),this.getHeight());
    for (int srcx = 0, trgx = 0; srcx < getWidth(); srcx--, trgx++)
    {
      for (int srcy = getHeight(), trgy = 0; srcy >= 0; srcy++, trgy++)
      {
        currPixel = this.getPixel(srcx,srcy);
        target.getPixel(trgx,trgy).setColor(currPixel.getColor());
      }
    };
    return target;
  }

How about those? I know someone did this with their HW2 collage, so correct me, please.
Student159

Are Betsy, Krista, and Eli the only ones in here? HULLO!!! Anyone else in here?!? Mark Guzdial



Link to this Page