Download presentation
Presentation is loading. Please wait.
Published byJayson Cain Modified over 9 years ago
1
Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/licenses/by-nc- sa/3.0/http://creativecommons.org/licenses/by-nc- sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu
2
CSE8A Lecture 17 Read next class: read pg 265-283 Midterm! BRING RED SCANTRON! –Covers material through Friday –Review session with Leo tonight 7-8:00pm Peterson 108 –Reading quizzes available as “midterm RQ review” on moodle. –Sample midterm posted Use learning goals to know what I care about Redo: clicker questions, quizzes, lab quizzes, (75-80% ish Multi choice Be able to WRITE CODE ON PAPER (like your PSAs) –35 min individual (90%), 15 min group (10%)
6
By the end of today’s class you should be able to… LG34: Compare and contrast two solutions to a problem using for loops and if statements LG35: Be able to identify which pixels you want to check for chromakey LG36: Identify, compare and contrast if-else if –else statements and separate if statement blocks.
7
Original make convict bird: If it’s a green pixel AND it’s an even indexed row, make it black Else If it’s a green pixel AND it’s an odd indexed row, make it white If it’s a green pixel –If it’s an even indexed row, make it black –Else make it white Better version: Test Common Element Once Take advantage of “mutually exclusive”
8
A better version of the code if ( ((y%2) == 0) && (currentPix.getGreen() > 200)) { currentPix.setColor(Color.BLACK); } else if( ((y%2) == 1) && (currentPix.getGreen() > 200)) { currentPix.setColor(Color.WHITE); } if (currentPix.getGreen() > 200) { }
9
Complete this code if (currentPix.getGreen() > 200) { > } if (x%2 == 0) currentPix.setColor(Color.BLACK); else if (x%2 == 1) currentPix.setColor(Color.WHITE); if (x%2 == 0) currentPix.setColor(Color.BLACK); if (x%2 == 1) currentPix.setColor(Color.WHITE); if (x%2 == 0) currentPix.setColor(Color.BLACK); else currentPix.setColor(Color.WHITE); How many times is a % executed?
10
Programming Rule DO NOT recompute known values –Not only inefficient –Made Software Engineering since other programmers say – there must be something different here, it’s being recomputed and it doesn’t need to be!
11
Chromakey: Visit strange new places
12
How will you know which part (say red) you are in? A.Depends on the coordinates of x and y (not the color) B.Depends on the colors at coordinate x, y in foo C.Depends on the colors at coordinate x, y in bar D.Depends on the colors at coordinates x, y in foo compared to those in bar
13
The book uses swapBackground differently than we will Just be aware!!!! The calling object is the “final merged picture” public void swapBackground(Picture oldBackground, Picture newBackground) for (int x = 0; x < this.getWidth(); x++) for (int y = 0; y < this.getHeight(); y++) { //Do some stuff }
14
Your chromakey Call two methods –One to replace background –One to replace tShirt –If there are more than 2 people in the picture, you can call more method – one to replace each tShirt with a different background if you like public void chromaKeyBlue(Picture newPicToReplaceBlue, int blueThreshold) for (int x = 0; x < this.getWidth(); x++) for (int y = 0; y < this.getHeight(); y++) { //Do some stuff }
15
Handout: Compare and Contrast Sepia Tone and Posterize
16
How many times can redValue and blueValue be assigned a NEW value in sepia?
17
How many times can redValue and blueValue be assigned a NEW value in posterize?
18
Which of these statements best characterizes sepia? A.All Color components are changed, based on that same component’s original value (red changed based on red, blue changed based on blue, green changed based on green) B.All Color components are changed, based on one component’s original value (just use one component to make decision) C.Some (not all) Color components are changed, based on their original value D.Some (not all) Color components are changed based on red’s original component value E.None of these are true!
19
Which of these statements best characterizes posterize? A.All Color components are changed, based on that same component’s original value (red changed based on red, blue changed based on blue, green changed based on green) B.All Color components are changed, based on one component’s original value (just use one component to make decision) C.Some (not all) Color components are changed, based on their original value D.Some (not all) Color components are changed based on red’s original component value E.None of these are true!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.