12_using_datatypes - Data Types 3.1 Using Data Types Data...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 3.1 Using Data Types 2 Data Types Data type. Set of values and operations on those values. Primitive types. Ops directly translate to machine instructions. We want to write programs that process other types of data. Colors, pictures, strings, input streams, … Complex numbers, vectors, matrices, polynomials, … Points, polygons, charged particles, celestial bodies, … Operations Set of Values Data Type not, and, or, xor true , false boolean double int add, subtract, multiply any of 2 64 possible reals add, subtract, multiply -2 31 to 2 31 - 3 Objects Object. Holds a data type value; variable name refers to object. Impact. Enables us to create our own data types; define operations on them; and integrate into our programs. length, substring, compare sequence of characters String Operations Set of Values Data Type get red component, brighten 24 bits Color Picture get/set color of pixel (i, j) 2D array of colors 4 Constructors and Methods To construct a new object: Use keyword new and name of data type. To apply an operation: Use name of object, the dot operator , and the name of the method .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Image Processing 6 Color Data Type Color. A sensation in the eye from electromagnetic radiation. Set of values. [RGB representation] 256 3 possible values, which quantify the amount of red, green, and blue, each on a scale of 0 to 255. 255 0 105 G R Color B 7 Color Data Type Color. A sensation in the eye from electromagnetic radiation. Set of values. [RGB representation] 256 3 possible values, which quantify the amount of red, green, and blue, each on a scale of 0 to 255. API. Application Programming Interface. http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.html 8 Albers Squares Josef Albers. Revolutionized the way people think about color. Homage to the Square by Josef Albers (1949-1975)
Background image of page 2
3 9 % java AlbersSquares 9 90 166 100 100 100 Albers Squares Josef Albers. Revolutionized the way people think about color. 10 Using Colors in Java public class AlbersSquares { { } } to access Color library first color second color first square second square 11 Monochrome Luminance Monochrome luminance. Effective brightness of a color. NTSC formula. Y = 0.299 r + 0.587 g + 0.114 b . import java . awt . Color ; public class Luminance { public static double lum ( Color c ) { int r = c . getRed (); int g = c . getGreen (); int b = c . getBlue (); return .299 * r + .587 * g + .114 * b ; } } 12 Color Compatibility Q. Which font colors will be most readable with which background colors on computer monitors and cell phone screens? A. Rule of thumb: difference in luminance should be 128. public static boolean compatible ( Color a , Color b ) { return Math . abs ( lum ( a ) - lum ( b )) >= 128.0 ; } 208 256 28 14 105 47
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 13 Grayscale Grayscale. When all three R, G, and B values are the same, resulting color is on grayscale from 0 (black) to 255 (white). Convert to grayscale. Use luminance to determine value. Bottom line. We are writing programs that manipulate color .
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/21/2009 for the course COMPUTER computer 1 taught by Professor Abedauthman during the Fall '08 term at Aarhus Universitet.

Page1 / 15

12_using_datatypes - Data Types 3.1 Using Data Types Data...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online