1 / 12

Creative Commons Attribution Non-Commercial Share Alike License

Creative Commons Attribution Non-Commercial Share Alike License. http://creativecommons.org/licenses/by-nc-sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu. CSE8A Lecture 14. Read next class: read pg 193-197 Grades – expectations Feedback: Review solutions to quizzes

kitty
Download Presentation

Creative Commons Attribution Non-Commercial Share Alike License

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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. 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

  3. Chapter 6: Conditionally modifying pixels Overview 3types: All pixels change if COORDINATES meet criteria All pixels change if meet both a COLOR and COORDINATE criteria All pixels change is COLOR meets criteria

  4. 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); } } } Yes, since we are changing the bottom half, we have to “fill in” across the rows in the inner loop Yes, because we need to make sure the if statement is checking aaa not bbb Yes, I have my own explanation No, the if statement controls the assignment

  5. How many times is the variable pix assigned a value? 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); } } } • 1 • this.getWidth() times • this.getHeight() times • this.getHeight()* this.getWidth() times • this.getHeight()/2* this.getWidth() times

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

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

  8. How many iterations of the loop body are executed? 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); } } } • getHeight()-1 * getWidth()-1 • getHeight()-1 * (getWidth()-1)/2 • getHeight() * getWidth() • getHeight() * getWidth()/2 • None of the above

  9. 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); } } } Show missign {} tp Control two statements A) if(bbb<this.getWidth()/2) B) if(bbb<this.getHeight()/2) C) if ((bbb % 2) == 0) D) if ( (this.getPixel(bbb,aaa) % 2) == 0)

  10. 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

  11. What parameters would YOU provide a user for a red eye reduction method? • Top left pixel coordinates for box to look for red eye in • Bottom right pixel coordinates for box to look for red eye in • Start index and end index for location to look for red eye in. • Color to change red eyes to • Threshold value to determine if eyes are “red”

  12. Book code for RedEye reduction:Parameters for good Software Engineering public 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( ); } } } Is there anything else We could parameterize?

More Related