1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Minchanka [31]
3 years ago
11

Write the method mirrorVerticalRightToLeft that mirrors a picture around a mirror placed vertically from right to left.

Computers and Technology
1 answer:
AURORKA [14]3 years ago
3 0

Answer:

Here is the method mirrorVerticalRightToLeft

public void mirrorVerticalRightToLeft()  {  //method definition

 Pixel[][] pixels = this.getPixels2D();  //uses getPixels2D() method which returns a two-dimensional array of Pixel object and stores this in pixels

 Pixel leftPixel = null;  //Pixel object leftPixel set to null

 Pixel rightPixel = null;  //Pixel object rightPixel set to null

 int width = pixels[0].length;  // returns the length of 0-th element of pixels and assigns it to width

 for (int row = 0; row < pixels.length; row++) {  //iterates through the rows of pixels array

  for (int col = 0; col < width / 2; col++)  {  //iterates through the columns of pixels array

   leftPixel = pixels[row][col];  //sets leftPixel to a certain point of row and column  of pixel array

   rightPixel = pixels[row][width - 1 - col];  //sets rightPixel to a certain point of row and column  of pixel array

   leftPixel.setColor(rightPixel.getColor());  }  }  } //uses object leftPixel to call setColor() method to set color of leftPixel to specified color and rightPixel is used to call getColor method to get the current color

Explanation:

The method mirrorVerticalRightToLeft is used to mirror a picture around a mirror placed vertically from right to left. It uses two loops, the outer loop iterates through each row and inner loop iterates through columns as long as the col variable stays less than width / 2 whereas width is set to pixels[0].length which compute the length of 0-th pixel. At each iteration we have the two position instance variables i.e. leftPixel and rightPixel such that leftPixel is set to pixels[row][col] and rightPixel is set to pixels[row][width - 1 - col]; For example if row = 0 and col = 0 then

leftPixel = pixels[0][0] which means it is positioned at 0th row and 0th column of 2D pixels array so it is positioned at the 1st pixel/element. It works this way at each iteration.

rightPixel = pixels[row][width - 1 - col]; for same example becomes:

rightPixel = pixels[0][width - 1 - 0];

So whaterbe is the value of width, the rightPixel is positioned at 0th row and width-1th column. Now after each of leftPixel and rightPixel  is placed to the desired pixel of pixels array then next the statement: leftPixel.setColor(rightPixel.getColor()); executes in which leftPixels calls setColor which sets the color to the specified color and rightPixel calls getColor method to get the current color. Suppose getColor returns the color blue so this color is set to leftPixel and this is how the picture is mirrored.

You might be interested in
All the network nodes are connected to each other
Shalnov [3]
It’s a mesh topology
7 0
3 years ago
How do graphic designers showcase their work?
Luda [366]

They showcase it digitally since their work is done on computers.

6 0
4 years ago
Read 2 more answers
Sidney works in the accounting department. His boss just assigned him a task that involves creating budget formulas for the comp
Molodets [167]
The answer is a A. - Excel performs operations based on the order of Precedence
4 0
3 years ago
The packet storm web site includes a large collection of packaged shellcode, including code that can:_____.
elena55 [62]

The packet storm web site includes a large collection of packaged shellcode, including code that can create a reverse shell that connects back to the hacker, flush firewall rules that currently block other attacks, and set up a listening service to launch a remote shell when connected to.

6 0
2 years ago
Which describes the "Network Effect?
KIM [24]

Answer:

phenomenon

Explanation:

Increased numbers of people or participants improve the value of a good or service.

3 0
3 years ago
Other questions:
  • How many results are shown by default when using a Top or Rare Command?
    13·1 answer
  • EDI decreases ______
    15·1 answer
  • Which step comes between identifying i need and generating ideas in a technological design process
    10·1 answer
  • In step 4 of the CSMA/CA protocol, a station that successfully transmits a frame begins the protocol to transmit a second frame
    9·1 answer
  • If you get your foot stuck in a cloud how many colors can you smell with you ears
    8·1 answer
  • Observe the following statements and decide whether the variable result’s value is TRUE or FALSE.
    13·1 answer
  • Does technology shape society or does society shape technology?
    14·1 answer
  • Which of the statements below is true?
    15·1 answer
  • When a file is used by a program, there are three steps that must be taken:
    7·1 answer
  • 2
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!