Fall 2005 Midterm Review - Color-blind
redGreenOut(picture)
for px in getPixels(picture):
green=getGreen(px)
red=getRed(px)
setGreen(px,(green+red)/2)
setRed(px,(green+red)/2)
look up. I forgot my colon for the first line, and my indentations aren't showing for some reason.
| Make sure you remember your def at the beginning. -poof #10 |
def example():
if (this.worked):
print "I am indented and look like code"
| type <code> before your code and </code> after it and it will take care of the indentations if you put them in.-poof #10 |
def redGreenOut(picture):
for px in getPixels(picture):
green = getGreen(px)
red = getRed(px)
avg = (green + red)/2
setGreen(px, avg)
setRed(px, avg)
why wont that work?!?!
| First add the colon to the end of line 2. Also, because your setGreen and setRed aren't part of the for loop, it'll only work for the bottom-right-hand pixel ONLY while leaving the rest of the picture unmodified. -Blake O'Hare |
def redGreenOut(picture):
for px in getPixels(picture):
green = getGreen(px)
red = getRed(px)
avg = (green + red)/2
setGreen(px, avg)
setRed(px, avg)
better??
def redGreenOut(pict):
for p in getPixels(pict):
nred = getRed(p)
ngreen = getGreen(p)
setRed(p, (nred+ngreen)/2)
setGreen(p, (nred+ngreen)/2)
Why doesn't this work?
| Seems to work fine here. Perhaps you're not passing in a valid picture? -Blake O'Hare |
why dont we repaint or return these?
| You don't need to. Repaint is only for when you want the picture to be visible. Return is unnecessary for passed in objects. -Blake O'Hare |
What is the function to make a number an integer? I realized that the problem was that when you average the red and green you sometimes get a float and need to make it into an integer. Otherwise, JES won't let you set a float to RGB values.
disregard that last entry
Link to this Page