{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs026_7_Part1

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

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

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.

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

View Full Document
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
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(“.”); }

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

View Full Document
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(); }
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?

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

View Full Document
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
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(); }

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

View Full Document
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
9 Review: Pictures as a Grid of Pixels • Recall that pictures are

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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
Ask a homework question - tutors are online