Download presentation
Presentation is loading. Please wait.
Published byMartina Ray Modified over 9 years ago
1
COSC 1P02 Introduction to Computer Science 7.1 Cosc 1P02 Week 7 Lecture slides "There are two ways of constructing a software design; one way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C. A. R. Hoare
2
COSC 1P02 Introduction to Computer Science 7.2 Choosing a Color Set color of each pixel Sequence through all pixels Picture is a collection for-each ASCIIPrompter to get RGB values Pixel class methods to get & set color of pixels Example Color constructor allows setting RGB Black & white Gray if R=G=B we get gray different shades with different intensities
3
Pixel Methods
4
COSC 1P02 Introduction to Computer Science 7.4 Grayscale Convert a picture into grayscale essentially what we call a black and white picture shades of gray indicating the luminance of the picture Gray if R=G=B set RGB to same value average of RGB values Color methods Example Note method may change the color of the pixels of the Picture parameter they stay changed just like a method moving a turtle changes its position
5
Color Methods
6
COSC 1P02 Introduction to Computer Science 7.6 Color Blindness Inability do distinguish some colors Red-green color blindness affects 5% of males deuteranopia – red and green receptors trigger at same level test Example set red and green values to same level (as green) PictureDisplayer(picture) constructor creates displayer that fits the picture and places the picture on displayer note display now declared in method not class depends on picture loaded local to method constructor does no initialization
7
COSC 1P02 Introduction to Computer Science 7.7 Rods and Cones
9
COSC 1P02 Introduction to Computer Science 7.9 Random Paint Create a picture by setting randomly chosen pixels to randomly chosen colors Start with a white canvas (picture) Select a random pixel pixels are arranged in two dimensions (width x height) can access a particular pixel via getPixel(x,y) x is x-coordinate (column) y is y-coordinate (row) top left corner is (0,0) bottom right corner is (height,width) Example picture attributes (width, height) random color random R, G, and B values
10
COSC 1P02 Introduction to Computer Science 7.10 Rotating a Picture 90 degree rotation to the left Rotated picture has different dimensions Pixel movement e.g. 3x2 picture (x,y) -> (y,width-1-x) Sequence through pixels of original producing new by setting pixels nested for loops y indexes through rows x indexes through columns Example displayer that sizes to picture need two displayers pictures different shapes garbage collection when display no longer references first displayer with no references, the storage for the object is reclaimed
11
(0,0) -> (0,2) (0,1) -> (1,2) (1,0) -> (0,1) (1,1) -> (1,1) (2,1) -> (1,0) (2,2) -> (2,0) 012 0 123 1 456 01 0 36 1 25 2 14
12
COSC 1P02 Introduction to Computer Science 7.12 Redeye Correction Flash reflecting from back of eye shows red in picture Change red to black (pupil) cannot change all red pixels or real red gets changed Select area to apply correction use some tool (e.g. PictureInspector ) to determine area What is red? many shades of red, not only (255,0,0) want colors close to red Color distance distance in 3 dimensional (R,G,B) space Example constant declaration ( TOLERANCE ) indexing over subrange of picture distance method sqrt & pow from Math
13
Euclidian Distance
14
COSC 1P02 Introduction to Computer Science 7.14 Colour Distance
15
COSC 1P02 Introduction to Computer Science 7.15 Picture Methods
16
COSC 1P02 Introduction to Computer Science 7.16 PictureDisplayer Methods
17
COSC 1P02 Introduction to Computer Science 7.17 The end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.