12
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]

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0

Embed Size (px)

Citation preview

Creative Commons AttributionNon-Commercial Share Alike

License• http://creativecommons.org/licenses/by-

nc-sa/3.0/

• Original Developer: Beth Simon, [email protected]

CSE8A Lecture 14• Read next class: read pg 193-197

• Grades – expectations

• Feedback:– Review solutions to quizzes

– Review clicker questions

– Review PSAs (with others and tutors)

– Review labs

Chapter 6: Conditionally modifying pixels

All pixels change is COLOR meets criteria

All pixels change if meet both a COLOR and COORDINATE criteria

All pixels change if COORDINATESmeet criteria

Does the order of the for loops matter?

public void fillBottom(Color newColor){ Pixel pix; for (int aaa = 0; aaa < this.getHeight(); aaa++) { for (int bbb = 0; bbb < this.getWidth(); bbb++) { <<<SELECT LINE OF CODE>>>> { pix = this.getPixel(bbb,aaa); pix.setColor(newColor); } }}A. Yes, since we are changing the bottom half, we

have to “fill in” across the rows in the inner loopB. Yes, because we need to make sure the if

statement is checking aaa not bbb C. Yes, I have my own explanationD. No, the if statement controls the assignment

How many times is the variable pix assigned a value?

A. 1B. this.getWidth() timesC. this.getHeight() timesD. this.getHeight()* this.getWidth() timesE. this.getHeight()/2* this.getWidth() times

public void fillBottom(Color newColor){ Pixel pix; for (int aaa = 0; aaa < this.getHeight(); aaa++) { for (int bbb = 0; bbb < this.getWidth(); bbb++) { <<<SELECT LINE OF CODE>>>> { pix = this.getPixel(bbb,aaa); pix.setColor(newColor); } }}

Remember this code?public void everyOtherPixel(Color newColor){ Pixel[] pixArray = this.getPixels(); for (int i = 0; i < pixArray.length(); i = i + 2) { pixArray[i].setColor(newColor); } }}

How is this the same?public void everyOtherColumn(Color newColor){ Pixel pix; for (int aaa = 0; aaa < this.getHeight(); aaa++) { for (int bbb = 0; bbb < this.getWidth(); bbb = bbb + 2) { pix = this.getPixel(bbb,aaa); pix.setColor(newColor); } }}

How many iterations of the loop body are executed?

A. getHeight()-1 * getWidth()-1B. getHeight()-1 * (getWidth()-1)/2C. getHeight() * getWidth()D. getHeight() * getWidth()/2E. None of the above

public void everyOtherColumn(Color newColor){ Pixel pix; for (int aaa = 0; aaa < this.getHeight(); aaa++) { for (int bbb = 0; bbb < this.getWidth(); bbb = bbb + 2) { pix = this.getPixel(bbb,aaa); pix.setColor(newColor); } }}

Same code with if statement control

public void everyOtherColumn(Color newColor){ Pixel pix; for (int aaa = 0; aaa < this.getHeight(); aaa++) { for (int bbb = 0; bbb < this.getWidth(); bbb++) {

<<SELECT LINE OF CODE TO GO HERE>> pix = this.getPixel(bbb,aaa); pix.setColor(newColor); } }}

A) if(bbb<this.getWidth()/2)

C) if ((bbb % 2) == 0)

B) if(bbb<this.getHeight()/2)

D) if ( (this.getPixel(bbb,aaa) % 2) == 0)

If you can do it both ways, which is “better”?

• Efficiency

• Software Engineering Design– Readability

– Modifyability

• We just looked at:– Looping over restricted bounds (< or %2 ==

0)

– Looping over all bounds with if statement inside

What parameters would YOU provide a user for a red

eye reduction method?1. Top left pixel coordinates for box to look for red

eye in2. Bottom right pixel coordinates for box to look for

red eye in3. Start index and end index for location to look for

red eye in.4. Color to change red eyes to5. Threshold value to determine if eyes are “red”

1 2 3 4 5

A X X X X X

B X X X X

C X X X

D X X X

E X X X

Book code for RedEye reduction:Parameters for good Software

Engineeringpublic void removeRedEye(int startX, int startY, int endX, int endY, Color newColor ){ Pixel pix; for (int x = ; x < ; x++) { for (int y = ; y < ;y++) { pix = this.getPixel(x,y); if (pix.colorDistance(Color.red) < 167) pix.setColor( ); } }}