Write a JavaScript program that has a function named swapRedGreen with one parameter pixel. This function should swap the red and green values of the pixel. Pick an image, print the image, then apply swapRedGreen to every pixel in the image, and print the new image. The choice of your image is important. For some images you may not notice any change. Think about what type of image you should use for testing your function.




// write your code here
function swapRedGreen(pixel){
    G = pixel.getGreen();
    R = pixel.getRed();
    if (G >= 200 ){
        pixel.setRed(255);
        pixel.setGreen(0);
        return true
    }
    if (R >= 200){
        pixel.setRed(0);
        pixel.setGreen(255);
        return true;
    }
}
var image = new SimpleImage("smallhands.png");
print (image);
for (pixel of image.values()){
    pixel = swapRedGreen(pixel);
}
print (image);



Comments

Popular posts from this blog

Choose Your Social Media Channels Week 5 Quiz