My current objective is to write a program that generates a square with dimensions of 200 pixels by 200 pixels. The square should be colored using specific RGB values: red (red value of 255), green (green value of 255), blue (blue value of 255), and magenta (red value of 255, blue value of 255). Any other RGB values should be set to 0. However, there seems to be a bug in my code as the output displays colors like yellow, green, magenta, and blue instead of just red. How can I correct this issue to achieve the desired red color? You can find my code snippet below:
var img = new SimpleImage(200,200);
for (var px of img.values()){
var x = px.getX();
var y = px.getY();
if (x < img.getWidth()/2){
px.setRed(255);
}
if (y > img.getHeight()/2){
px.setBlue(255);
}
else {
px.setGreen(255);
}
}
print (img);