Programming Languages Chapter 5 The Focus This Modifying Pixels Twodimensional Array Using Nested For

subject Type Homework Help
subject Pages 2
subject Words 620
subject Authors Barbara Ericson, Mark J. Guzdial

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 5
The focus in this chapter is on modifying pixels in a two-dimensional array using nested for
loops. You can have students play battleship to show that we work with two-dimensional arrays
all the time. We motivate working with two-dimensional arrays by mirroring pictures from left
to right and from top to bottom. We motivate working with ranges by mirroring just part of a
picture. Be sure to let students use their own pictures! They have fun creating pictures of people
with two heads. Challenge students to figure out how to mirror on a diagonal line. Show how to
break the problem down into a simpler problem (use just numbers in a simple two-dimensional
array) and ask what the solution would be. Tell them that they can’t write a program to do
In section 5.2 we show having more than one variable change in a for loop. We motivate this by
copying pixels from one picture to another. Again we create methods that are not the most
reusable and slowly show how to make them more reusable. We also blend two pictures
together to show that you can use more than one for loop in a method. We rotate an image to
show that you can use the loop variables in different ways. We scale a picture up or down to
show that you don’t always need to add one to the loop variables. We also point out that an
You can also show students another way to rotate an image. A Turtle object can take a picture
and drop it (draw it with the top left at the current turtle location and rotated to match the turtle
heading). This can give you some nice effects. Turtles can be created on Pictures so you can use
this to copy one picture to another as well (Figure 7).
Figure 7. Flower1.jpg dropped while turtle is turning in a loop
At this point we recommend that you ask the students to create an image collage. The collage
should have at least 4 images (it can be the same image or different images) in the collage with
different image manipulations done to them (like reduce red, negate, grayscale, rotate, clip, etc)
page-pf2
and then mirror the collage. We find that students enjoy creating collages of their images. In
fact, we have had students turn in collages and keep working on them because they aren’t quite
what they want yet. We recommend that you encourage students to post their work so that others

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.