Friday, 1 July 2016

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 ){
        return true
    if (R >= 200){
        return true;
var image = new SimpleImage("smallhands.png");
print (image);
for (pixel of image.values()){
    pixel = swapRedGreen(pixel);
print (image);

No comments:

Post a Comment