Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"— Presentation transcript:

1 Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/licenses/by-nc- sa/3.0/http://creativecommons.org/licenses/by-nc- sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@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 1)Create a picture from a specific file 2)Create a picture that is a copy of another picture 3)Create a picture of width X and height Y 4)Create a picture of the same width and height as another picture Call A.Picture p=new Picture(); B.Picture p=new Picture(“filename.jpg”); C.Picture p=new Picture(other); D.Picture p=new Picture(aNum,bNum);

8 Mirroring Around Vertical Axis

9 Code to Mirror Around Vertical Axis: From Left to Right 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 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()); }

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

15 Review: What does this code do? 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--; } A.Copies top half into bottom half not mirrored. B.Copies left half into right half not mirrored. C.Mirrors around vertical axis, left into right D.Mirrors around horizontal axis, top into bottom E.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--; } A.Copies top half into bottom half not mirrored. B.Copies left half into right half not mirrored. C.Mirrors around vertical axis, left into right D.Mirrors around horizontal axis, top into bottom E.Some other bizarre transformation


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"

Similar presentations


Ads by Google