Creative Commons Attribution NonCommercial Share Alike License http
Creative Commons Attribution Non-Commercial Share Alike License • http: //creativecommons. org/licenses/by-ncsa/3. 0/ • Original Developer: Beth Simon, 2009 bsimon@cs. ucsd. edu
CSE 8 A Lecture 10 • Read next class: read pg 142 -152 • PSA 3 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);
By the end of today’s class you should be able to… • LG 22: Read and code nested loops to perform mirroring (and related) transformations using nested loops.
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 < get. Width(); foo++) { for (int bar 0; bar < get. Height(); bar++) { p = get. Pixel(foo, bar); p. set. Color(Color. BLACK); } }
Nested Loops: How do they work? What order are pixels changed? • A method in Picture. java… Pixel p; for (int bar = 0; bar < get. Height(); bar++) { for (int foo = 0; foo < get. Width(); foo++) { p = get. Pixel(foo, bar); p. set. Color(Color. BLACK); } }
What do these methods do? What are their return values? • get. Pixel(int x, int y) • get. Height() • get. Width()
Why does this have an error? • A method in Picture. java… Pixel p; for (int bar = 0; bar < get. Width(); bar++) { for (int foo = 0; foo < get. Height(); foo++) { p = get. Pixel(foo, bar); p. set. Color(Color. BLACK); } } A. It doesn’t, this loops across rows, going down B. It doesn’t, this loops down columns, going right C. It tries to index a pixel off the end of a row (foo value too big) D. It tries to index a pixel off the end of a column (bar value too big)
- Slides: 7