tags:

views:

86

answers:

3

http://tinypic.com/r/fwubzc/5

That shows what a flip should be and what a mirror should be.

Code for both types of mirrors:

void mirrorLeftRight()
{
    for (int x = 0; x < width/2; x++) {
            for (int y = 0; y < height; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[width-x][y]
                pixelData[width-x][y]=temp;
            }
    }
}

void mirrorUpDown()
{
    for (int x = 0; x < width; x++) {
            for (int y = 0; y < height/2; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[x][height-y]
                pixelData[x][height-y]=temp;
            }
    }
}

Does this seem right for mirrors?

And for flip, just a matter of using width and height w/o dividing by 2?

+2  A: 

You need to use width-1-x instead of width-x, and height-1-y instead of height-y. Otherwise for x==0 you'll try to index [width], which is outside the array.

interjay
+3  A: 

It shouldn't work since you are swapping pixels while you just have to override the right part of the image with the left part. Same thing applies to the mirrorUpDown.

If you swap them you obtain a flip, if you overwrite them you obtain a mirror.

  • mirrorLeftRight: take pixels from left half and use them to overwrite right part
  • mirrorUpDown: take pixels from upper part and use them to overwrite lower one
  • flip: in this case you don't overwrite but you swap pixels (source half it's not influent in this case)
Jack
so my examples are flips, not mirrors.what do i change to make that code a mirror?
codefail
since it's homework you should try to figure out by yourself :) I already gave you enough hints..
Jack
A: 

The code above seems more like the correct way to Flip, not mirror.

Mirror I would guess that you not switch the pixels, but rather copy from one side to the other.

With mirror I would guess that you need to change

int temp = pixelData[x][y]; 
pixelData[x][y]=pixelData[width-x][y] 
pixelData[width-x][y]=temp;

to something like this only

pixelData[x][y]=pixelData[width-x][y] 
astander