1 / 16

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 11. Read next class: read pg 152-162 Finish PSA3 and do an interview!

briana
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 11 • Read next class: read pg 152-162 • Finish PSA3 and do an interview! • Check out the cool stuff on the wiki and post! • ANNOUNCEMENT: • Society of Hispanic Professional Engineers Meeting • TONIGHT: 7-8pm! • EBU1 Room 4140 (Second Floor) • FREE PIZZA! • http://shpe.ucsd.edu

  3. Discussion in Groups • We only do this because it’s been shown to improve learning. • Discussion is critical: prepare and JUST DO IT. • Also, you only get clicker points if your group votes the same thing… • Starting now (since some people didn’t understand) • We work HARD to give you the best learning experience • We expect your honest effort as well

  4. Discussion Group: Rotating Leaders • Each member of the group should be ONE icon. • Each day in class, we’ll have one person “leading” your discussion group. • We’ll announce it at the beginning of class • If you have only 4 people, one icon will be “wild” and anyone can lead discussion that day

  5. Today the discussion leader is

  6. By the end of today’s class you should be able to… • LG22: Read and code nested loops to perform mirroring (and related) transformations using nested loops. • LG23: Select an appropriate constructor method for “making a new Picture” • LG24: Employ the technique of drawing examples to explore various cases with 2-D array manipulation. • LG25: Read, trace, and write code that performs a transformation over a restricted set of pixels (like a “box” of pixels).

  7. Match the scenario to the constructor call (we’ll vote for each scenario) Scenario Call Picture p=new Picture(); Picture p=new Picture(“filename.jpg”); Picture p=new Picture(other); Picture p=new Picture(aNum,bNum); • Create a picture from a specific file • Create a picture that is a copy of another picture • Create a picture of width X and height Y • Create a picture of the same width and height as another picture

  8. Mirroring Around Vertical Axis

  9. Code to Mirror Around Vertical Axis:From Left to Right int mirrorPt = getWidth()/2; Pixel leftP, rightP; for (int y = 0; y < getHeight); y++) { for (int x = 0; x < mirrorPt; x++) { leftP = getPixel(x,y); rightP = getPixel(getWidth()-1-x,y); rightP.setColor(leftP.getColor()); } • Which of the following is the BEST answer: A) y increases faster than x B) x increases faster than y C) x and y increase together, in step D) x increases for a while, then y increases once, then x restarts and increases again E) Y increases for a while, then x increases once, then y restarts and increases again

  10. Mirroring Around Vertical Axis:Left to Right • What are the parameter values we use to index leftPixel and rightPixel for the first three iterations of the loop? (assume picture has a height = 50 and width = 100) int mirrorPt = getWidth()/2; Pixel leftP, rightP; for (int y = 0; y < getHeight); y++) { for (int x = 0; x < mirrorPt; x++) { leftP = getPixel(x,y); rightP = getPixel(getWidth()-1-x,y); rightP.setColor(leftP.getColor()); } }

  11. How do you figure these kinds of questions out? • Answer: Draw a diagram • imagine “beginning” and “answer” • Draw arrows to show how to get from beginning to answer • Then fill in numbers in order, write loops to create those numbers

  12. Mirroring Even pixels versus Odd pixels int mirrorPt = getWidth()/2; ... for (int x = 0; x < mirrorPt; x++)

  13. Mirror versus “flip” (PSA4) (around vertical axis)

  14. What is the order of topP and bottomP coords for mirroring around horizontal axis? • Give first 4 iterations Does it matter bottom into top Or top into bottom? NO What would assignment statements be?

  15. Review: What does this code do? ISOMORPHIC don’t show results • Hint, you probably need to trace the getPixel index values. int magic = getWidth()/2; Pixel foo, bar; for(int y = 0; y < getHeight(); y++) { int countingDown = getWidth()-1; for(int x = 0; x < magic; x++) { foo = getPixel(x,y); bar = getPixel(countingDown,y); bar.setColor(foo.getColor()); countingDown--; } } Copies top half into bottom half not mirrored. Copies left half into right half not mirrored. Mirrors around vertical axis, left into right Mirrors around horizontal axis, top into bottom Some other bizarre transformation

  16. Practice for the quiz: • Modify the code to do… (choose the various options) int magic = getWidth()/2; Pixel foo, bar; for(int y = 0; y < getHeight(); y++) { int countingDown = getWidth()-1; for(int x = 0; x < magic; x++) { foo = getPixel(x,y); bar = getPixel(countingDown,y); bar.setColor(foo.getColor()); countingDown--; } } Copies top half into bottom half not mirrored. Copies left half into right half not mirrored. Mirrors around vertical axis, left into right Mirrors around horizontal axis, top into bottom Some other bizarre transformation

More Related