Unit 5 - Lesson 10 shifting image

I am baffled by the “Shifting a 2d Array” project in Lesson 10. The suggested solution requires the use of getters and setters to repaint pixels. This is not shifting pixels. I do not understand why I can’t just move existing pixel objects in the array, as we did for example in reversing arrays. There are times in the CSA curriculum where I feel that we don’t know everything we need to know about the Theater and Image Classes, and this is one. Is there something special about a Pixel object the prevents me from moving it in an array? If I’m using a getter to read a Pixel color in one index location, and using a setter to modify a Pixel color in another index location, I haven’t shifted anything. I’ve modified colors of existing pixels. Why can’t I just move Pixel objects in the array? jr

@jranta - Hi John. I understand how this may seem like another exercise of moving objects in an array. It is my impression that this exercise (Unit 5 Lesson 10 Level 4C) is intended to have the students manipulate the attributes of the object and not just move the object around. The objective is to take the pixel (access it) and transform it (set it to a random color). If I am looking at the wrong level, please let me know.
I hope this helps. Please feel free to reach out with any further questions.

Yes, that is the assignment I’m talking about. I understood it differently. I read it to mean students should take the pixel objects in the image array, and shift them some number to the left, to display a shifted image. This should be easy to do, but it isn’t with code.org pixels. When students write a set of nested loops to shift the pixels in the array, nothing happens. The shifted image is the same as the original (and there are no error messages). I can’t figure out why this is, nothing in the documentation explains it. With other arrays of objects, it is a fairly simple operation to move objects to a different index location in an array. What is it about code.org’s pixel and image classes that prevent this? I want to explain to my students why they have to use the getters and setters to over-write pixel values, instead of just shifting pixel objects, but I don’t understand it myself. Can someone explain? Thanks, jr

Let me take a closer look.

Hi John, I see how this can be confusing since the rest of the lesson is just moving objects around. Pixels act differently since they are primarily a given color. For this reason, the colors must be accessed and set to the “new” location to simulate the shift. I hope that makes sense.

I understand that pixels are different, because of how they’re behaving when we create these methods. I don’t understand why they’re different. Why can’t we move the pixels in the array? Is there something special about a pixel array that locks their positions? That’s my basic question. jr

@jranta - I did a little research since I don’t have a log of experience with the Pixel class. My interpretation is that a pixel is a combination of colors. From that viewpoint, the color is the object and the object is the color. Pixels do act differently than other objects and require a set and get method to shift the colors around the array. I hop this makes sense. I found this documentation on the web that adds to what is posted in Code.org.

1 Like