CS 101 – Sept. 16
description
Transcript of CS 101 – Sept. 16
![Page 1: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/1.jpg)
CS 101 – Sept. 16
• Finish color representation– RGB √
– CMY
– HSB
– Indexed color
• Chapter 4 – how computers think– Begin with basic building blocks
![Page 2: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/2.jpg)
Color rep’ns
• RGB – system based on light
• CMY – based on printing
• HSB – based on art
• Indexed color – a swatch to save space
![Page 3: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/3.jpg)
RGB system
• Based on primary colors for light
• Each pixel has (red, green, blue) values.
• Examplesblack = (0, 0, 0)
purple = (75, 0, 100)
white = (255, 255, 255)
• How about (x, x, x) or (0, 0, x) ?
![Page 4: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/4.jpg)
RGB examplesColor R G B
black 0 0 0
white 255 255 255
red 255 0 0
green 0 255 0
blue 0 0 255
cyan 0 255 255
magenta 255 0 255
yellow 255 255 0
![Page 5: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/5.jpg)
CMY system
• Based on primary colors of printing
• Each pixel has (cyan, magenta, yellow) values
• In contrast to RGB:white = (0, 0, 0)
black = (255, 255, 255)
![Page 6: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/6.jpg)
CMY examplesColor C M Y
white 0 0 0
black 255 255 255
cyan 255 0 0
magenta 0 255 0
yellow 0 0 255
red 0 255 255
green 255 0 255
blue 255 255 0
![Page 7: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/7.jpg)
Practical notes
• Printout may look different to screen
• Ex. RGB blue = (0, 0, 255)
but CMY blue = (255, 255, 0)
In other words, in color printer, 2 different toners required to produce blue.
• CMY, a.k.a. CMYK
![Page 8: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/8.jpg)
HSB system
• From artistic standpoint, neither RGB nor CMY makes much sense to people
• More intuitive color definition:– Hue = what color you want– Saturation = how much of that color– Brightness
![Page 9: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/9.jpg)
HSB geometry• Hue = which direction
on color wheel
• Saturation = how far from center
• Brightness = how far up or down
![Page 10: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/10.jpg)
hue
saturation
brightness
Trade-off between saturation and
brightness
![Page 11: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/11.jpg)
Indexed color
• Do we really need 16,777,216 colors?– ~ 200 is more practical
• Indexed color is like RGB:– 6 values of each primary color, not 256– Hex values: 00, 33, 66, 99, cc, ff
• 1 byte per pixel instead of 3
• Dithering to simulate in-between colors
![Page 12: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/12.jpg)
Chapter 4
Begin chapter on computer organization
• Logic gates– Used to perform math operations
• Later: finite automata– basic model of computation
![Page 13: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/13.jpg)
Logic Gates
• Basic building blocks• Usually 2 inputs• X, Y could be 0 or 1.
1 = true0 = false
• By combining 2+ gates, you get more sophisticated functions
![Page 14: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/14.jpg)
‘AND’ and ‘OR’
AND
X Y ans
1 1 1
1 0 0
0 1 0
0 0 0
OR
X Y ans
1 1 1
1 0 1
0 1 1
0 0 0
![Page 15: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/15.jpg)
Adder
• We can teach the computer how to add using just a few logic gates.
• However, we need to look at one more gate, the XOR.
![Page 16: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/16.jpg)
Exclusive or (XOR)
• XOR basically says “either, but not both”
• The output is 1 if both inputs are different.
XOR
X Y Ans
1 1 0
1 0 1
0 1 1
0 0 0
![Page 17: CS 101 – Sept. 16](https://reader035.fdocuments.us/reader035/viewer/2022062315/5681580c550346895dc57c2c/html5/thumbnails/17.jpg)
Adder
• Here is the logic to add, one bit at a time.