Transcript lec10Colors

Colors
• Colors can be made of mixtures of 3 primary
colors.
• If the medium is illumination (like on the face of a
CRT) the colors are often called Red, Green and
Blue.
• If the medium is absorption (like paint or ink) the
colors are often called Magenta, Yellow and Cyan
(what some of us call red, yellow and blue).
• In the Analog world, the saturation range can be
very smooth.
Computer Screen Colors
1
Digital Colors
• In digital systems (for example in computer
screens) there is a stepwise range of saturation for
each of the 3 colors.
• Many modern systems allow for 256 levels of
saturation ranging from 0 (black) to 255
(brightest) for each of the three colors.
• This can not be demonstrated in black and white
print but running the program “colors.exe” in the
class directory allows you to examine it.
Computer Screen Colors
2
Digital Colors
• This illustrates the
appearance of an orange
colored plate with a blue
saturation of 0, a green
saturation of 152/256 and
a red saturation of 250/256
• With 256 shades of each
of 2 colors, a total of
16,777,216 different
colors are available. This
color is color #39162.
Computer Screen Colors
3
Digital Colors
• A better understanding can be achieved if we look at the
color numbers as binary values.
• The binary system is the basis of the numbers and symbols
used in a computer.
• Binary numbers have just two values (0,1) and computer
switches and logic gates also have two values (on,off)
Computer Screen Colors
4
Binary & Hexadecimal Numbers
Dec.
•
•
•
•
•
•
•
•
8 4 2 1 Hex.


 


0
1
2
3
4
5
6
7
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
0
1
0
1
0
1
0
1
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
Dec.

•
•
•
•
•
•
•
•
Computer Screen Colors
8
9
10
11
12
13
14
15
8 4 2 1 Hex.





1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
8
9
A
B
C
D
E
F
5
Decimal and Hexadecimal
• The color to the right,
DarkCyan, is made up of
139 parts of blue and 126
parts of green.
• In Hex those numbers are
8B and 7E.
• In binary they are
10001011 and 01111110.
• This is color number
9,141,760 decimal or
8B7E00 hexadecimal.
Computer Screen Colors
6
A Binary Exercise
•
•
The binary number
10001011 base 2 is
identical to 139 base 10.
In the decimal world, the
number 139 can be
written as:
• In the binary world the
same procedure yields:
1 X 100 = 100
3 X 10 = 30
9 X
1 = + 9
Total
139
Computer Screen Colors
1 x 128
0 x 64
0 x 32
0 x 16
1 x
8
0 x
4
1 x
2
1 x
1
Total
= 128
=
0
=
0
=
0
=
8
=
0
=
2
= + 1
= 139
7
A Hexadecimal Exercise
• In the binary world the
number 139 works out:
1 x 128
0 x 64
0 x 32
0 x 16
1 x
8
0 x
4
1 x
2
1 x
1
Total
= 128
=
0
=
0
=
0
=
8
=
0
=
2
= + 1
= 139
• In the hexadecimal world,
the number 8B yields:
8 x 16 = 128
B or 11 x
1 = +11
Total
= 139
Computer Screen Colors
8
The Number of a Color
• Thus the color whose
decimal number is
9,141,760 has a
hexadecimal number of
8B7E00.
• It is nearly impossible to
determine the color from
the decimal number but
easy from the hexadecimal
number.
Computer Screen Colors
9
Coding Color into Visual Basic
• In the hexadecimal world the decimal equivalent to
8B7E00 is:
8 8 x 1048576
B 11 x
65536
7 7 x
4096
E 14 x
256
0 0 x
16
0 0 x
1
Total
=
=
=
=
=
=
=
8388608
720896
28672
3584
0
+
0
9141760
Computer Screen Colors
10
Coding Color into Visual Basic
You can use these numbers in your programs. A line of code
in Visual Basic like:
Label1.BackColor = 9141760
or:
Label1.BackColor = &H8B7E00
will make the background of Label1 DarkCyan.
Computer Screen Colors
11
The Internet and Color
• The Internet uses a different format for colors.
• Rather than the Blue-Green-Red that Visual Basic uses, the
Internet uses Red-Green-Blue.
• So color 8B7E00 hex or 9,141,760 dec in Visual Basic
becomes color 007E8B hex or 32,395 dec on the Internet.
• The problem is handled internally, you will see no
problem.
Computer Screen Colors
12