Lab 2: Rose-Colored Glasses or Jaded

15
Lab 2: Rose-Colored Glasses or Jaded Michael Stewart

description

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 : - PowerPoint PPT Presentation

Transcript of Lab 2: Rose-Colored Glasses or Jaded

Page 1: Lab 2: Rose-Colored Glasses or Jaded

Lab 2: Rose-Colored Glasses or Jaded

Michael Stewart

Page 2: Lab 2: Rose-Colored Glasses or Jaded

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

Page 3: Lab 2: Rose-Colored Glasses or Jaded

New JES methods

• pixel.getRed…• color.getRed…• setColor(pixel, newColor)• distance(color1, color2)

• dir

Page 4: Lab 2: Rose-Colored Glasses or Jaded

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

Page 5: Lab 2: Rose-Colored Glasses or Jaded

Conditionals and Branching

http://xkcd.com/210/

Page 6: Lab 2: Rose-Colored Glasses or Jaded

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”

Page 7: Lab 2: Rose-Colored Glasses or Jaded

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()

Page 8: Lab 2: Rose-Colored Glasses or Jaded

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.

Page 9: Lab 2: Rose-Colored Glasses or Jaded

Boolean (cont’d.)

• Let’s try some in the command window:• 1 > 2• 1==1• True and False• Not True

A B A and B A or B

True True True True

True False False True

False True False True

False False False False

Page 10: Lab 2: Rose-Colored Glasses or Jaded

Lab Assignment

• Download the skeleton for the lab from today’s page

• Start with an image like this

Page 11: Lab 2: Rose-Colored Glasses or Jaded

Lab Assignment (cont’d.)

• First, tint the image to a desired color, like this:

Page 12: Lab 2: Rose-Colored Glasses or Jaded

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:

Page 13: Lab 2: Rose-Colored Glasses or Jaded

Lab Assignment (cont’d.)

What’s the difference?!

Page 14: Lab 2: Rose-Colored Glasses or Jaded

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.

Page 15: Lab 2: Rose-Colored Glasses or Jaded

Lab Assignment (cont’d.)

• Submit your work to the Lab 2 Moodle assignment