Peer Instruction: Unit 3 Multiple Choice Questions¶
- A
- Incorrect! The code compares the top pixel (topP) and the pixel below it (botP). If they are similar, then the top pixel becomes white; else, it becomes black. Since each vertical column is composed of the same color, the pixels on top and below will always be the same color, turning all pixels white. The lines between the different colors are still composed of the same color vertically, so they wouldn't turn black.
- B
- Incorrect! The code compares the top pixel (topP) and the pixel below it (botP). If they are similar, then the top pixel becomes white; else, it becomes black. Since each vertical column is composed of the same color, the pixels on top and below will always be the same color, turning all pixels white.
- C
- Correct! The code compares the top pixel (topP) and the pixel below it (botP). If they are similar, then the top pixel becomes white; else, it becomes black. Since each vertical column is composed of the same color, the pixels on top and below will always be the same color, turning all pixels white.
- D
- Incorrect! The code compares the top pixel (topP) and the pixel below it (botP). If they are similar, then the top pixel becomes white; else, it becomes black. Since each vertical column is composed of the same color, the pixels on top and below will always be the same color, turning all pixels white.
- E
- Incorrect! One of the answers above represents the code accurately. The code compares the top pixel (topP) and the pixel below it (botP). If they are similar, then the top pixel becomes white; else, it becomes black. Since each vertical column is composed of the same color, the pixels on top and below will always be the same color, turning all pixels white.
16-6-1: What’s the result of running this pixel-adjusting code on this green, red, and purple input?
//Inside loop over all pixels
topP = this.getPixel(x,y);
botP = this.getPixel(x,y+1);
topAvg = topP.getAverage();
botAvg = botP.getAverage();
if (Math.abs(topAv – botAv) < 10)
{
topP.setColor(Color.WHITE);
}
else
{
topP.setColor(Color.BLACK);
}
You have attempted of activities on this page