lundi 25 mai 2020

How do I correct a bug

I am trying to write a program that draws a square 200 pixels by 200 pixels, square with colors red (red value 255), green (green value 255), blue (blue value 255) and magenta (red value 255 and blue value 255). All other RGB values are set to 0. However, my code has a bug, and produces a rather yellow, green, Magenta and Blue. How do I get the Red colour instead the yellow? Below is my code.

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);

Aucun commentaire:

Enregistrer un commentaire