Fall 2007 Test 1 Review: Generalized changeColor
Post questions here.
Are we going to have to write our own functions like this on the test?
| Maybe. But the increaseRed() and decreaseRed() functions are in the book, and so if you practice this, you can refer to them. In a test, which is closed-book, you would be given the code that you were being asked to modify – not be expected to remember it. You will not be asked to write a function from scratch. Either you will be asked to modify a given function, or will be asked to write a function, with another related function being given as a hint. Colin Potts |
"changeColor(pic, 0, 'blue') should do nothing at all to the amount of blue in the picture (or red or green for that matter)."
This is the part I'm not so sure about....What would do so that even if you imput 0, the function will take in as the current value1, as opposed to changing that color to zero, which would obviously alter the picture? Any ideas?
def changeColor(pic):
for all pixels in getPixels(picture):
Red=getRed(pixel)
Blue=getBlue(pixel)
Green=getGreen(pixel)
now im stuck also what page is the decreaseRed() function on again?
| This was fun, and by fun I mean it was hard. My code / guess as follows: |
def changeColor(fn,value,color):
pic = makePicture(fn)
for p in getPixels(pic):
if(color==red):
setRed(p,getRed(p)*(1+value))
if(color==green):
setGreen(p,getGreen(p)*(1+value))
if(color==blue):
setBlue(p,getBlue(p)*(1+value))
show(pic)
Alex Young
seems good to me. this one is tricky
| There's still a small problem. red is shorthand for the color red (i.e. 255,0,0) but "red" in quotes is a text string. In the examples, the color names are quoted, meaning that you should be comparing the third input argument with those strings not with actual colors. Colin Potts |
| Here's my revision. Alex Young |
def changeColor(fn,value,color):
pic = makePicture(fn)
for p in getPixels(pic):
if(color=="red"):
setRed(p,getRed(p)*(1+value))
if(color=="green"):
setGreen(p,getGreen(p)*(1+value))
if(color=="blue"):
setBlue(p,getBlue(p)*(1+value))
show(pic)
why is there parenthesises and why is there two = signs?
| The == means "if something is equal" as opposed to = meaning "this equals that". The parenthesis are not necessary. Thanks! Brittany Duncan |
| More specifically, x == y is a comparison operator, meaning you're checking to see if x and y have the same value. x = y, on the other hand, is an assignment operator, meaning you're taking the value in y and putting it into the x variable. Joshua Cuneo |
Link to this Page