Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/ sa/3.0/ Original Developer: Beth Simon, 2009
CSE8A Lecture 17 Read next class: read pg 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%)
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.
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”
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) { }
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?
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!
Chromakey: Visit strange new places
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
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 }
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 }
Handout: Compare and Contrast Sepia Tone and Posterize
How many times can redValue and blueValue be assigned a NEW value in sepia?
How many times can redValue and blueValue be assigned a NEW value in posterize?
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!
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!