Introduction

In lecture this week, you learned about looping in JavaScript. You will apply the use of JavaScript by transforming an image by changing the color of every pixel. For example, the first filter you will build is:

Download, Extracting, and Opening the Lab

Download and Extract the Lab

To get started, first download the ZIP file for Lab 3 here. Extract the folder.

Opening the HTML in a Web Browser

Inside of the folder with the extracted file, open the myInstagram.html file using either Chrome or Firefox. (It may be necessary to right-click the file and choose "Open With".)

Opening the JavaScript in a Text Editor

For this lab, you will be working it filters.js.

On a lab machine, Notepad++ is an ideal text editor for this class. To open Notepad++:

  1. Open the Start Menu on the lab computer
  2. Choose All Programs
  3. Choose Word Processing
  4. Choose Notepad++

Completing the Lab

SimpleImage API

Throughout this lab and your MP, you will be using variables that are of SimpleImage data type. These variables are not Numbers or Strings, but instead are images that can be manipulated through methods that you can call on the variable.

If you have a variable SIMPLEIMAGE of data type SimpleImage, you can use the properties and methods from the following list.

Important: Your variable is not called SIMPLEIMAGE. You need to use either origImg or newImg that are passed into your function!

Part 0: Find an Image

Grab an image from your photos, the Internet, or anywhere to use as part of this lab. Save it to your desktop or somewhere you can easily access. This photo should not be black and white as we will be playing with the hues of colors, so black and white photos don't really work.


Part 1: Creating an X-Ray Filter

In fliters.js, an empty function called filter_xray has been defined for you. To complete this function, you should create an X-Ray Filter. To do that, for every pixel:

In order to do this, you need to loop through every pixel. Since an image is a width by a height, we need to go through every pixel by looping through the width and then, inside of the width loop, looping through the height.

Test your code now!

At this point, make sure that you and your team members all have the receipt displaying the correct information for all the code you have completed to this point. Make sure you understand the code you have written so far. The next part will build on the understanding of this first part.

Part 2: Illinify an Image (Extra Credit -- Worth +1, Graded Individually)

In this part, we will explore the pixels by their HSL color. To "Illinify" an image, we will convert the image to be only hues of blue and orange, leaving the shading, saturation, and luminosity of each pixel the same.

First, go to http://hslpicker.com/ and find a good value for the hue of an Illini colored orange and blue (the top-most slider). Make sure to write down the hue values for both orange and blue.

Next, come up with an algorithm:

Write a new function that implements that algorithm:

Finally, add your new filter to the list of filters. Find the filters variable at the bottom of your filters.js and copy and paste the line of code for the X-Ray filter. Update the fields to call your new filter (this includes updating both the name value and the func value with the name of your new funciton.

Test your code now!

At this point, make sure that you and your team members all have the receipt displaying the correct information for all the code you have completed to this point. Make sure you understand the code you have written so far. The next part will build on the understanding of this first part.

Part 3: Illinify an Image Even More! (Extra Credit -- Worth +1, Graded Individually)

While our second filter did a great job turning the images to shades of orange and blue, we want more orange and blue!

Copy the entirety of the function (make sure to rename the name of the variable that you are assigning the function as you cannot have the same variable twice) you used to complete Part 2 and add the following logic for every pixel:

Just like Part 2, add your new filter to the filters variable at the bottom.

Submission

To submit your lab, you must submit your filters.js to the CS 105 website. You should submit ONLY .js file. You do not need to submit the other files in the folder. Click here to submit the lab!

Because this is a ZIP file, you must extract it in order to work on the files