// write your code here
//Get the green screen image
var greenScreen = new SimpleImage("drewRobert.png");
//Get a background image
var background = new SimpleImage("dinos.png");//Use the green screen image to make a new image that combines green screen and background
var greenWidth = greenScreen.getWidth();
var greenHeight = greenScreen.getHeight();
var finalImage = new SimpleImage (greenWidth, greenHeight);
//Set a green pixel tolerance--change and see results
var greenTolerance = 200;
function makeGreenScreen() {
//Loop through all the pixels of greenScreen
for(var pixel of greenScreen.values()) {
//Get the coordinates of current pixel
var x = pixel.getX();
var y = pixel.getY();
//Determine if green pixel is above tolerance
if(pixel.getGreen() > 247){
var backgroundPix = background.getPixel(x, y);
finalImage.setPixel(x, y, backgroundPix);
}
else {
//Set it to the green screen pixel
finalImage.setPixel(x, y, pixel);
}
}
//Change the 3 to whatever will make the image fit your screen
finalImage.setSize(greenWidth/4, greenHeight/4);
print(finalImage);
}
//Call the above function
makeGreenScreen();
// write your code here
var picture = new SimpleImage("palm-and-beach.png");
print (picture);
function maxRed() {
for(var pixel of picture.values()) {
//Make any modifications below
var grayValue = (pixel.getRed()/3 + pixel.getGreen()/3 + pixel.getBlue()/ 3)
pixel.setRed(grayValue);
pixel.setGreen(grayValue);
pixel.setBlue(grayValue)
}
print(picture)
}
//maxRed();
function negative() {
for(var pixel of picture.values()) {
//Make any modifications below
pixel.setRed(255 - pixel.getRed());
pixel.setGreen(255 - pixel.getGreen());
pixel.setBlue(255 - pixel.getBlue());
}
print(picture)
}
negative();