View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Mirror diagonal method

See Diagonal Mirror Questions for what diagonal mirroring means

  /**
   * Method to mirror around a diagonal line from width-1,0 to 0,height-1
   */
  public void mirrorDiagonal()
  {
    Pixel leftPixel = null; // left of diagonal line
    Pixel rightPixel = null; // right of diagonal line
    int width = getWidth(); // the width of this picture
    int height = getHeight(); // the height of this picture
    
    // if the width is greater than the height reset width to height
    if (width > height)
      width = height;
    // else if the height is greater than the width use width for height
    else if (height > width)
      height = width;
    
    // get last x and y for the mirroring
    int lastX = width - 1; // last valid x index
    int maxX = lastX;
    int lastY = height - 1; // last valid y index
    
    // loop through the rows (from 0 to max Y)
    for (int y = 0; y < lastY; y++,maxX--)
    {
      // loop through the columns
      for (int x = 0; x < maxX; x++)
      {
        leftPixel = getPixel(x,y);
        rightPixel = getPixel((lastX - y), (lastY - x));
        rightPixel.setColor(leftPixel.getColor());
      }
    }
  }


Link to this Page