150 likes | 272 Views
Lab 2: Rose-Colored Glasses or Jaded. Michael Stewart. Colors as points in 3D color space. Today we will continue to take advantage of the distance between two colors as representing those colors’ similarity. This is facilitated by our encoding of color. One way to view this encoding is :
E N D
Lab 2: Rose-Colored Glasses or Jaded Michael Stewart
Colors as points in 3D color space • Today we will continue to take advantage of the distance between two colors as representing those colors’ similarity. • This is facilitated by our encoding of color. • One way to view this encoding is : • http://en.wikipedia.org/wiki/File:RGB_color_solid_cube.png
New JES methods • pixel.getRed… • color.getRed… • setColor(pixel, newColor) • distance(color1, color2) • dir
Driver Function • Sometimes when programming, you may want to test many different functions • Or you may want to test a function that requires several arguments • Writing one function which makes these tedious calls for you can be useful
Conditionals and Branching http://xkcd.com/210/
Conditionals and Branching (cont’d.) • So far our code has been rather declarative • However we can write recipes that perform differently in different circumstances. • This is usually called “branching” or “conditionals”
Conditionals and Branching (cont’d.) • The simplest kind of branch statement is the “if” statement. • In this example, the function “doSomething” will only be called sometimes. if somethingIsTrue: doSomething()
Boolean • In normal numerical arithmetic, you use numerical operators (+, -, *, /) and multiple numbers, to produce a numerical result. • In BOOLEAN arithmetic, you use boolean operators (==, <, >, not, and, or, etc.), and multiple boolean/numerical values(True, False), to produce a boolean result.
Boolean (cont’d.) • Let’s try some in the command window: • 1 > 2 • 1==1 • True and False • Not True
Lab Assignment • Download the skeleton for the lab from today’s page • Start with an image like this
Lab Assignment (cont’d.) • First, tint the image to a desired color, like this:
Lab Assignment (cont’d). • Swap Roles with your partner. • Now, change the color of a certain range of colors. So using the same starting point as tint, produce this:
Lab Assignment (cont’d.) What’s the difference?!
Lab Assignment (cont’d.) In the first picture, you’re making every pixel closer to the target color. In the second, you only change pixels of similar color to a color of your choice.
Lab Assignment (cont’d.) • Submit your work to the Lab 2 Moodle assignment