TWiki
>
CS101 Web
>
CS101Spring2012
>
S12Exam2Solutions
(2012-04-16, Main.troy)
(raw view)
E
dit
A
ttach
CS 101 Exam 2 Solutions 1 D 1 D 1 D 1 A 1 A 1 E 1 A 1 C 1 B 1 A 1 C 1 C 1 A 1 B 1 B 1 A 1 C 1 D 1 A 1 C 1 <hr /> <pre> =// method to make a 5 color posterized version of a picture= </pre><pre> =public static Picture q21 (Picture p)= </pre><pre> ={= </pre><pre> =int xPos, yPos;= </pre><pre> =int wid = p.getWidth();= </pre><pre> =int hgt = p.getHeight();= </pre><pre> =// loop for all the x values= </pre><pre> =for ( xPos = 0 ; xPos < wid ; ++xPos )= </pre><pre> ={= </pre><pre> =// loop for the the Y values= </pre><pre> =for ( yPos = 0 ; yPos < hgt ; ++yPos )= </pre><pre> ={= </pre><pre> =// access a pixel= </pre><pre> =Pixel pix = p.getPixel (xPos, yPos);= </pre><pre> =// access the color values of that pixel= </pre><pre> =int red = pix.getRed ();= </pre><pre> =int green = pix.getGreen ();= </pre><pre> =int blue = pix.getBlue ();= </pre><pre> =// modify the color values of the pixel= </pre><pre> =int grayAmount;= </pre><pre> =grayAmount = (int)Math.round((red * 0.299) + (green * 0.587) + (blue * 0.114)) ; if ( grayAmount < 255 / 5 ) // 51= </pre><pre> ={ pix.setColor ( Color.BLACK );= </pre><pre> =}= </pre><pre> =else if ( grayAmount < 2 * 255 / 5 ) // 102= </pre><pre> ={ pix.setColor ( Color.BLUE ); }= </pre><pre> =else if ( grayAmount < 3 * 255 / 5 ) // 153= </pre><pre> ={ pix.setColor ( Color.GREEN ); }= </pre><pre> =else if ( grayAmount < 4 * 255 / 5 ) // 204= </pre><pre> ={ pix.setColor ( Color.CYAN );= </pre><pre> =}= </pre><pre> =else= </pre><pre> ={ pix.setColor ( Color.WHITE); }= </pre><pre> =}= </pre><pre> =}= </pre><pre> =return p;= </pre><pre> =}= </pre><pre> 22.</pre><pre> =// method to make a color negtive from a picture= </pre>
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2012-04-16 - 22:27:18 - Main.troy
CS101
Syllabus
Lecture Notes
Homeworks
Additional Material
[edit this menu
]
Log In
CS101 Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
ABOUT US
Our Department
Recent News
Contact Us
ACADEMICS
Prospective Students
Undergraduate
CS Minor
Graduate
Courses
RESEARCH
Overview
By Faculty
Labs
PEOPLE
Faculty
Adjuncts
Staff
Students
Alumni
Copyright 2016 The Board of Trustees
of the University of Illinois.
webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF