The function swapRedGreen has one parameter, a pixel. This function swaps the red and green values and returns the resulting red, green and blue values somehow. Which one of the following is the correct code for this function?

// write your code here
function swapRedGreen(pixel) {
     var newGreen = pixel.getRed();
     var newRed = pixel.getGreen();
     pixel.setGreen(newGreen);
     pixel.setRed(newRed);
     return pixel;
}
var image = new SimpleImage ("eastereggs.jpg");
print (image);
for ( var pixel of image.values()){
    if (swapRedGreen(pixel) ){
       
    }
   
}
print (image);

Comments

  1. What is the different??
    var img3 = new SimpleImage ("eastereggs.jpg");

    for (var pixel of img3.values()){
    if (pixel.getX() <= img3.getWidth()){
    pixel.setRed(pixel.getGreen());
    pixel.setGreen(pixel.getRed());
    }
    }

    print (img3);

    ReplyDelete

Post a Comment

Popular posts from this blog

Choose Your Social Media Channels Week 5 Quiz