Top Banner
Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/license s/by-nc-sa/3.0/ • Original Developer: Beth Simon, 2009 [email protected]
12

Creative Commons Attribution Non-Commercial Share Alike License

Mar 18, 2016

Download

Documents

Payton

Creative Commons Attribution Non-Commercial Share Alike License. http://creativecommons.org/licenses/by-nc-sa/3.0/ Original Developer: Beth Simon, 2009 [email protected]. THIS LECTURE GOT WRITTEN OVER!. Re develop from older ones – there were some new slides in Fa 2009, so get those from UP. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Creative Commons Attribution Non-Commercial Share Alike License

Creative Commons AttributionNon-Commercial Share Alike

License• http://creativecommons.org/licenses/by-nc-sa/3.0/

• Original Developer: Beth Simon, [email protected]

Page 2: Creative Commons Attribution Non-Commercial Share Alike License

THIS LECTURE GOT WRITTEN OVER!• Re develop from older ones – there were

some new slides in Fa 2009, so get those from UP.

Page 3: Creative Commons Attribution Non-Commercial Share Alike License

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

Page 4: Creative Commons Attribution Non-Commercial Share Alike License

About group quizzes and learningA. Group quizzes are great, I really learn a

lotB. Group quizzes are good, it helps me

solidify my learning to discuss the questions with others

C. Group quizzes are OK, I’m not sure how much I learn by doing them

D. Group quizzes are not helpful to my learning at all.

Page 5: Creative Commons Attribution Non-Commercial Share Alike License

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

Page 6: Creative Commons Attribution Non-Commercial Share Alike License

Changing pixels all over, conditionally

What is it doing?A)Comparing 2 pixels side by side and, if they are similar make the pixel white, otherwise blackB)Comparing 2 pixels one on top of the other and, if they are similar make the pixel white, otherwise blackC)Comparing 2 pixels side by side and, if they are different make the pixel white, otherwise blackD)Comparing 2 pixels one on top of the other and, if they are different make the pixel white, otherwise black

//Inside loop over all pixelstopP = 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);

Page 7: Creative Commons Attribution Non-Commercial Share Alike License

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

Page 8: Creative Commons Attribution Non-Commercial Share Alike License

A DIFFERENT edgeDetect//Inside loop over all pixelstopP = 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);

Page 9: Creative Commons Attribution Non-Commercial Share Alike License

A DIFFERENT edgeDetect//Inside loop over all pixelstopP = 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);

Page 10: Creative Commons Attribution Non-Commercial Share Alike License

Which is most true about ONE execution of this code (for a specific diffValue)

A. Section A AND Section B may BOTH be executed

B. If Section B is executed then Section A is not executed

C. Neither Section is ever executed D. 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);

Page 11: Creative Commons Attribution Non-Commercial Share Alike License

Which is most true about ONE execution of this code (for a specific diffValue)

A. Section A can be executed AND Section B may BOTH be executed but then C can’t be executed

B. If Section A is executed then neither Section B nor C can be

C. All sections can be executed for a single diffValue

D. It’s possible no section is executed for a given 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);

Confused? See page 187 for execution flow diagram

Page 12: Creative Commons Attribution Non-Commercial Share Alike License

In Lab 5: Which best describes the conditions under which we change pixel color?

A. Based on the coordinates of the PixelB. Based on the color of the PixelC. Based on the coordinates for some Pixels, the color for

other PixelsD. Based on a compound condition of color and coordinates

of the Pixel

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); } }}