Fall 2007 Test 1 Review - Make Sunset
Post questions here.
here's my guess at the answers...
a)
def functionA(picture):
for pixel in getPixels(picture):
setRed(pixel,0)
setGreen(pixel, getGreen(pixel))
setBlue(pixel, getBlue(pixel))
b)
def functionB(picture):
for pixel in getPixels(picture):
setRed(pixel,getRed(pixel))
setGreen(pixel, getBlue(pixel))
setBlue(pixel, getGreen(pixel))
c)
def functionC(picture):
for pixel in getPixels(picture):
setRed(pixel,getRed(pixel))
setGreen(pixel, getRed(pixel))
setBlue(pixel, getRed(pixel))
One thing I am seeing in your functions pretty consistently is that you seem to feel a need to do something with the red, green, and blue values regardless of whether or not you are asked to do something with them. Is there a point to having a line in your code like: setRed(pixel,getRed(pixel)) ?? Why or why not? Toni Walden |
def functionA(picture):
for p in getPixels(picture):
setRed(p,0)
setGreen(p,0)
setBlue(p,0)
show(picture)
def functionB(picture):
for p in getPixels(picture):
setGreen(p,getBlue(p))
setBlue(p,getGreen(p))
show(picture)
| So do you want green and blue to both be equal to the original blue value? Thanks! Brittany Duncan |
| I think I see what I did incorrectly. The following functionB is my rewrite: Alex Young |
def functionB(picture):
for p in getPixels(picture):
newColor = makeColor(getRed(p),getBlue(p),getGreen(p))
setColor(p,newColor)
show(picture)
def functionC(picture):
for p in getPixels(picture):
setGreen(p,getRed(p))
setBlue(p,getRed(p))
show(picture)
Alex Young|
I thought that the first attempt at functionB was right. Isn't the only problem that the code setRed(pixel, getRed(pixel))
just redundant? That wouldn't change the value of the color, would it?
def functionB(picture):
for pixel in getPixels(picture):
setRed(pixel,getRed(pixel))
setGreen(pixel, getBlue(pixel))
setBlue(pixel, getGreen(pixel))
| This isn't correct, and I made the same mistake. Here's my understanding of why it isn't right: |
The second line in the for loop, the setGreen(...) function, changes all the green values in the pixels to be whatever the blue values are.
The third line changes all the blue values to be what the green values are, but wait! You've already changed the green values to be blue values, so you're setting blue to be blue.
Alex Young
| Hmm, my functionA was not right. |
def functionA(picture):
for p in getPixels(picture):
setRed(p,0)
show(picture)
| Just by the way, the for loop changes each pixel 1 by 1. So it doesn't change all the green values and then all the blue values. It changes the blue value of each pixel and then the green value of each pixel. Thanks! Brittany Duncan |
Link to this Page