Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License"— Presentation transcript:

1 Creative Commons Attribution Non-Commercial Share Alike License
Original Developer: Beth Simon, 2009

2 CSE8A Lecture 10 Read next class: read pg 142-152 PSA3 HINT: Collage
You should then create a picture that is the same height as the one you chose, but three times as wide. Picture foo = new Picture (100, 300); Turtle jose = new Turtle (25, 50, w);

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

4 Nested Loops: How do they work? What order are pixels changed?
DON’T REVEAL, VOTING OR DISCUSS ISOMORPHIC QUESTION NEXT Nested Loops: How do they work? What order are pixels changed? A method in Picture.java… Pixel p; for (int foo = 0; foo < getWidth(); foo++) { for (int bar 0; bar < getHeight(); bar++) p = getPixel(foo, bar); p.setColor(Color.BLACK); }

5 Nested Loops: How do they work? What order are pixels changed?
A method in Picture.java… Pixel p; for (int bar = 0; bar < getHeight(); bar++) { for (int foo = 0; foo < getWidth(); foo++) p = getPixel(foo, bar); p.setColor(Color.BLACK); }

6 What do these methods do? What are their return values?
getPixel(int x, int y) getHeight() getWidth()

7 Why does this have an error?
A method in Picture.java… Pixel p; for (int bar = 0; bar < getWidth(); bar++) { for (int foo = 0; foo < getHeight(); foo++) p = getPixel(foo, bar); p.setColor(Color.BLACK); } It doesn’t, this loops across rows, going down It doesn’t, this loops down columns, going right It tries to index a pixel off the end of a row (foo value too big) It tries to index a pixel off the end of a column (bar value too big)


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License"

Similar presentations


Ads by Google