Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Creative Commons Attribution Non-Commercial Share Alike License PowerPoint Presentation
Download Presentation
Creative Commons Attribution Non-Commercial Share Alike License

Creative Commons Attribution Non-Commercial Share Alike License

95 Vues Download Presentation
Télécharger la présentation

Creative Commons Attribution Non-Commercial Share Alike License

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Creative Commons AttributionNon-Commercial Share Alike License • http://creativecommons.org/licenses/by-nc-sa/3.0/ • Original Developer: Beth Simon, 2009bsimon@cs.ucsd.edu

  2. THIS LECTURE GOT WRITTEN OVER! • Re develop from older ones – there were some new slides in Fa 2009, so get those from UP.

  3. CSE8A Lecture 15 • Read next class: read pg 197-202 • Quizzes pick up

  4. About group quizzes and learning • Group quizzes are great, I really learn a lot • Group quizzes are good, it helps me solidify my learning to discuss the questions with others • Group quizzes are OK, I’m not sure how much I learn by doing them • Group quizzes are not helpful to my learning at all.

  5. By the end of today’s class you should be able to… • LG30: Write and read code that either loops over a subset of pixels or loops over all pixels and controls changes to pixels with and if statement • LG31: Use parameters to control looping in conditional setting of pixels • LG32: Identify the flow of control in the three types of Java if statements: if, if-else, and if-else if-else • LG34: Compare and contrast two solutions to a problem using for loops and if statements

  6. Changing pixels all over, conditionally //Inside loop over all pixels topP = this.getPixel(x,y); botP = this.getPixel(x,y+1); topAvg = topP.getAverage(); botAvg = botP.getAverage(); if (Math.abs(topAv – botAv) < 10) topP.setColor(Color.WHITE); else topP.setColor(Color.BLACK); What is it doing? Comparing 2 pixels side by side and, if they are similar make the pixel white, otherwise black Comparing 2 pixels one on top of the other and, if they are similar make the pixel white, otherwise black Comparing 2 pixels side by side and, if they are different make the pixel white, otherwise black Comparing 2 pixels one on top of the other and, if they are different make the pixel white, otherwise black

  7. What’s the result of running that code on this input?

  8. A DIFFERENT edgeDetect //Inside loop over all pixels topP = this.getPixel(x,y); botP = this.getPixel(x+1,y); // was (x,y+1) topAvg = topP.getAverage(); botAvg = botP.getAverage(); if (Math.abs(topAv – botAv) < 10) topP.setColor(Color.WHITE); else topP.setColor(Color.BLACK);

  9. A DIFFERENT edgeDetect //Inside loop over all pixels topP = this.getPixel(x,y); botP = this.getPixel(x+1,y); // was (x,y+1) topAvg = topP.getAverage(); botAvg = botP.getAverage(); if (Math.abs(topAv – botAv) < 10) topP.setColor(Color.WHITE); else topP.setColor(Color.BLACK);

  10. Which is most true about ONE execution of this code (for a specific diffValue) • Section A AND Section B may BOTH be executed • If Section B is executed then Section A is not executed • Neither Section is ever executed • It is possible neither Section will be executed (but sometimes one might be). int diffValue = Math.abs(topAv – botAv); if (diffValue < 10) topP.setColor(Color.WHITE); else topP.setColor(Color.BLACK);

  11. Which is most true about ONE execution of this code (for a specific diffValue) int diffValue = Math.abs(topAv – botAv); if (diffValue < 10) topP.setColor(Color.WHITE); else if (diffValue < 50) topP.setColor(Color.GREY); else topP.setColor(Color.BLACK); • Section A can be executed AND Section B may BOTH be executed but then C can’t be executed • If Section A is executed then neither Section B nor C can be • All sections can be executed for a single diffValue • It’s possible no section is executed for a given diffValue Confused? See page 187 for execution flow diagram

  12. In Lab 5: Which best describes the conditions under which we change pixel color? public void makeConvict() { for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { Pixel currentPix = this.getPixel(x,y); if ( (currentPix.getGreen() > 200) && (y%2==0)) { currentPix.setColor(Color.BLACK); } else if( (currentPix.getGreen() > 200) && y%2 == 1) { currentPix.setColor(Color.WHITE); } } } • Based on the coordinates of the Pixel • Based on the color of the Pixel • Based on the coordinates for some Pixels, the color for other Pixels • Based on a compound condition of color and coordinates of the Pixel