In your previous reading, we learned how to interact with a 2D representation of a Picture using nested loops. Now that we can work with the 2D representation, you will read about some of the many applications that work on this representation. You’ll learn how to do things like copy regions of a picture from one place to another and how to mirror a picture.
Sections 5.1.2 - 5.2.1 (pp. 134-149) from the course textbook.
Each student will be responsible for learning and demonstrating proficiency in the following objectives PRIOR to the class meeting. The reading quiz will test these objectives.
for
loop header that initializes more than one variable in the initialization area and changes more than one variables in the change area.The following objectives should be mastered by each student DURING and FOLLOWING the class session through active work and practice.
These exercises are geared towards mastering the BASIC learning objectives listed above. You are expected to submit them before class and it is highly recommended that you complete them before attempting the reading quiz.
Part A: Draw a 5x2 matrix of Pixels, writing the (x,y) coordinate inside of each pixel. It should look something like the following table, but with real numbers instead of a literal “(x,y)” for the coordinates.
(x,y) | (x,y) | (x,y) | (x,y) | (x,y) |
(x,y) | (x,y) | (x,y) | (x,y) | (x,y) |
Part B: Draw another 5x2 matrix of pixels that will represent the pixels from Part A after that have been mirrored vertically. Inside of each pixel, put the (x,y) coordinate where that pixel was found in the original matrix of pixels.
Part C: Repeat Part B, but this time the matrix should represent what happens after you mirror horizontally. Note it should be the mirror of the original (Part A) not the already mirrored picture (Part B).
I want to vertically mirror a part of a Picture centered at (100,100). The region to mirror should be 20 pixels wide and 50 pixels high. Based on this, calculate the following quantities:
Consider the following Java code.
int val = 0;
for (int i = 0; i < 10; i += 2) {
val = val + i;
}
Part A: For both i
and val
, list the sequence of values that those variables will be as we trace though the code. Your answer should look something like the following (with different values, of course):
i = 1, 2, 3, 4
val = 10, 20, 30, 40
Part B: Describe what this code does. (Remember: think “high level” for your description.)