Mirroring is done by copying. Suppose a Picture has H rows of Pixels and W columns of Pixels and W is an even number, like W is 2N. Here N is a the whole number that is exactly 1/2 of W. How many Pixels are copied when the Picture is mirrored along the vertical line through its middle? <-- I understand what the question is asking. Its just how would I go about doing it? Should I type up a program?

Recommended Answers

All 6 Replies

What are the coordinates for the pixels (source and target) as they are copied? Make a loop that copies the pixels for each row inside another loop that goes through the rows.

How many Pixels are copied when the Picture is mirrored along the vertical line through its middle?

Isn't the answer just "all of them" (H*W)? Or am I missing something?

public void mirrorVertical()
  {
    int width = this.getWidth();
    int mirrorPoint = width / 2;
    Pixel leftPixel = null;
    Pixel rightPixel = null;

   for(int y = 0; y < getHeight(); y++)
     {
       for(int x =0; x < mirrorPoint; x++)
        {
          leftPixel = getPixel(x,y);
          rightPixel = getPixel(width - 1- x, y);
          rightPixel.setColor(leftPixel.getColor());
       }
    }
  }

  public static void main(String[] args) 
  {
     String fileName = FileChooser.pickAFile();
     Picture pictObj = new Picture(fileName);
     pictObj.mirrorVertical();
     pictObj.repaint();
  }

This is what I have so far. I would have to change my for{} loops and add the source, target variables to count the copied pixels?

Can you explain the logic for what you want the code to do?
Make a list of the steps in pseudo code.

What happens when you compile and execute the code?

I want the code to display the number pixels that are copied when the Picture is mirrored along the vertical line.

In my for loop I added the variable count

int count =0;

for(int y = 0; y < getHeight(); y++)
     {
       for(int x =0; x < mirrorPoint; x++)
        {
          leftPixel = getPixel(x,y);
          rightPixel = getPixel(width - 1- x, y);
          rightPixel.setColor(leftPixel.getColor());

          count = count + 1;
       }
    }

When I run the code its displays 153600 for the number of pixels copied.
I realized the code muiltple (Height x Width) / 2.
So I am assuming my answer is correct for the question...

Counting the number moved doesn't mean that they were moved to the correct locations.

All the counting does is verify the product of width/2 * height

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.