If Statement Exercises

1.

In class, we created a diagonal from the bottom left corner to the top right corner. Instead, write code that will create a blue-green diagonal from the top left to the bottom right corner. Hint: try writing the x and y coordinates of the pixels in that diagonal. Do you notice any patterns?


 

2.

Using your code from question 1 and from class, modify x.png to have two diagonals in blue-green and all the rest of the pixels be colored orange.


 

3.

Write code to make the right half of flowers.jpg grayscale. Hint: you can use image.getWidth() or image.getHeight() to find the dimensions of the image in pixels.


 

4.

Write code to change all pixels with an average brightness less than 125 to black, and all pixels with an average brightness of at least 125 to white. The result should be a high-contrast, purely black-and-white image.


 

5.

Develop your own image filter! It can be anything you want (but please make it sufficiently different from something we did in class and especially from the other problems on this homework). You can use any image we've used in class. The opportunities are endless!

This is your opportunity to play around with if statements. What kinds of operations do you know? What sorts of properties of pixels might you care about? The more you play around with the code, the cooler the effect will be.


 


Each click of a Run button saves that code on the computer running the browser. The button below retrieves the all code exercises listed to the right of the button.

count 5 : if-ex1 if-ex2 if-ex3 if-ex4 if-ex5

(code appears here)