cs026_7_Part1

cs026_7_Part1 - Topic 6 Modifying Pixels in a Matrix Part 1...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Topic 6 Modifying Pixels in a Matrix Part 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Learning Goals • To understand at a conceptual and practical level Nested loops • Using nested loops to process data in a matrix (2-dimensional array) • More advanced topics with methods • More advanced ways of manipulating pictures in Java programs
Background image of page 2
3 Nested Loops • Suppose we wanted to print 50 dots in a row …………………………………………. . • We could do this with a for loop: for (int count = 1; count <=50; count ++) { System.out.print(“.”); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Nested Loops • Now suppose we wanted to print 5 rows of 50 dots each • We could use a for loop to count the rows: for (int row = 1; row <= 5; row ++) { // print 50 dots in a row for (int count = 1; count <=50; count ++) { System.out.print(“.”); } System.out.println(); }
Background image of page 4
5 Nested Loops • The for loop to print a row of dots is part of the body of the loop that counts the rows • This is an example of nested loops • The loop that counts the rows is called the outer loop • The loop that prints a row of dots is called the inner loop • Question: Why did we need the statement System.out.println(); after the inner loop here?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Nested Loops • Another example: print a triangle of dots . .. …. ….. • The outer loop would count the rows • The inner loop would print the appropriate number of dots
Background image of page 6
7 Nested Loops for (int row = 1; row <= 5; row ++) { // print dots in a row for (int count = 1; count <= ?? ; count ++) { System.out.print(“.”); } System.out.println(); }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 More Advanced Work with Pictures • We can only go so far in processing pictures without knowing where certain pixels are in an image, for example: • Cropping a picture • Copying just part of a picture • Performing reflections • Performing rotations • We will now consider a picture as a matrix or two dimensional array
Background image of page 8
9 Review: Pictures as a Grid of Pixels • Recall that pictures are
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/20/2009 for the course COMP SCI 026 taught by Professor Unknown during the Spring '07 term at UWO.

Page1 / 28

cs026_7_Part1 - Topic 6 Modifying Pixels in a Matrix Part 1...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online