Midterm Exam 1 Review Fall 2003: Generalized image filter
(Back to Fall2003 Midterm Review 1)
Answers? Comments? Comments on answers?
How about this-
def(change RGB (pict,ramount,gamount,bamount):
for pin getPixels(pict):
setRed(p,gerRed(p)(1+ramount))
setGreen(p,getGreen(p)(1+gamount))
setBlue(p,getBlue(p)(1+bamount))
| Check your syntax again, and see the FAQ page on how to format code on the CoWeb. Mark Guzdial |
def changeRGB(picture, r, g, b):
for px in getPixels(picture):
setRed(px,getRed(px)*(1+r))
setGreen(px,getGreen(px)*(1+g))
setBlue(px,getBlue(px) *(1+b))
| That looks good Lindsay, make sure you try to run it though. | |
I tried the following code in JES and it seems to work. However, is there any error in logic? Also, I didn't understand the part about incorporating numbers 1(for red), 2(for green), and so on. Do I need to add numbers to my code? If so, where and how?
def changeColor(pict):
for p in getPixels(pict):
setRed(p,getRed(p)*.90)
setGreen(p,getGreen(p)*1.30)
setBlue(p,getGreen(p)*0)
how does this look? None of the other posts included anything about the constraints, so i didn't know if we were supposed to, but it doesn't seem like it would work properly if they were just neglected...Also, I wasnt' sure if we could do the constraints with "or" in between
def changeRGB(pict, red, green, blue):
for p in getPixels(pict):
if red >= -.99 or <=.99:
setRed(p,getRed(p)&star(red+1)
if green >= .99 or <= .99:
setGreen(p,getGreen(p)&star(green+1)
if blue >= .99 or <= .99:
setBlue(p,getBlue(p)&star(blue+1)
| Very nice! You don't have to worry about such constraints for this problem, though. Mark Guzdial |
def changeRGB(picture, red,green,blue):
for px in getPixels(picture):
setRed(p,getRed(p)(red+1))
setGreen(p,getGreen(p)(green+1))
setBlue(p,getBlue(p)(blue+1))
When I format my code like this it allows me to load the program but when I try to make it run in the command area it will not do so. It tells me that a local or global code could not be found. Is there anything I need to fix? Do I type values or changeRGB(picture, red,green,blue) in the command area? Neither was working.
Ok, this obviosly did not indent the above but the 2nd line is 2 spaces and the following 3 are indented 4 spaces. Emily
| Go FAQ to learn how to format. |
def changeColor(picture, amount, colorcode):
for p in getPixels(picture):
if (amount >= -.99) and (amount = .99):
if colorcode == 1:
setRed(p,(getRed(p)(amount+1)))
if colorcode == 2:
setBlue(p,(getBlue(p)(amount+1)))
if colorcode == 3:
setGreen(p,(getGreen(p)(amount+1)))
It did not put in the less than sign on the third line. And they are indented. There should also be asterisks between (p) and (amount+1) in each setColor line.
That's 3 inputs. I wouldn't do the colorcode for this.
Here was my attempt at this problem... I think it is easy to read. Any feedback, critisism? Greg Leo
def changeRGB(pict,redamt,greenamt,blueamt):
if (-.99<=redamt<=.99) and (-.99<=greenamt<=.99) and (-.99<=blueamt<=.99):
for p in getPixels(pict):
oldred = getRed(p)
oldgreen = getGreen(p)
oldblue = getBlue(p)
newred = (oldred *(redamt+1))
newgreen= (oldgreen * (greenamt+1))
newblue= (oldblue * (blueamt+1))
newcolor= makeColor(newred,newgreen,newblue)
setColor(p,newcolor)
else:
end
I guess I'm just reverting to old habits. It really isn't needed. Greg Leo
Link to this Page