11. Consider writing a program to draw a square 200 pixels by 200 pixels that looks like the square below with colors red (red value 255), green (green value 255), and blue (blue value 255).
All other RGB values are set to 0.
Consider that the square is black to start out with. Examine the following code to draw this image that has one MISSING CONDITION to draw the blue pixels.
Which one of the following is the correct MISSING CONDITION to complete the program to draw the image above?
Solution
for (var p of image.values()) {
p.setRed(0);
p.setBlue(0);
p.setGreen(0);
x = p.getX();
y = p.getY();
if (y <= image.getHeight()/3) {
p.setRed(255);
}
else if (y >= image.getHeight()/3*2) {
p.setBlue(255);
}
else if (x <= image.getWidth()/3) {
p.setRed(255);
}
else {
p.setGreen(255);
}
}
print (image);
No comments:
Post a Comment