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);
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);
What is the different??
ReplyDeletevar 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);