Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Spring 2005: Generalized changeColor

Post your answers, questions, comments, comments on answers, suggestions, suggestions on questions, etc.

Back to Spring2005 Midterm 1 Review



def changeColor(picture, amount, type):
for p in getPixels(picture):
if (type==1):
setRed(p, getRed(p)(1+amount))
if (type==2):
setGreen(p, getGreen(p)(1+amount))
if (type==3):
setBlue(p, getBlue(p)(1+amount))

def changeColor(picture, amount, type):
for p in getPixels(picture):
if (type==1):
setRed(p, getRed(p)(1+amount))
if (type==2):
setGreen(p, getGreen(p)(1+amount))
if (type==3):
setBlue(p, getBlue(p)(1+amount))

how do you add indentions on this thing? i tried twice but it won't work and my code looks weird.

Check out the FAQ under the question, how do I get code to show up in the CoWeb. Kelly Lyons

def changeColor(picture, amount, type):
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
for p in getPixels(picture):
if(type==1):
setRed(p,red+(amountred))
if(type==2):
setGreen(p, green+(amountgreen))
if (type==3):
setBlue(p, blue+(amountblue))

I think this is the same as the ones above mine but it just does the math in a different order...let me know if im wrong

def changeColor(picture, amount, type):
for p in getPixels(picture):
if (type==1):
setRed(p, getRed(p) (amount + 1))
if (type==2):
setGreen(p, getGreen(p) (amount + 1))
if (type==3):
setBlue(p, getBlue(p) (amount + 1))





def changeColor(pict, percent, colornum):
if percent>-1 and percent1:
for p in getPixels(pict):
if (colornum==1):
setRed(p, getRed(p)(1+percent))
if (colornum==2):
setGreen(p, getGreen(p)(1+percent))
if (colornum==3):
setBlue(p, getBlue(p)(1+percent))
show(pict)
else:
show(pict)



def changeColor(picture, amount, color):
if amount > -1 and amount < 1:
for p in getPixels(picture):
if (color==1):
setRed(p, getRed(p) * (amount + 1))
if (color==2):
setGreen(p, getGreen(p) * (amount + 1))
if (color==3):
setBlue(p, getBlue(p) * (amount + 1))


why do none of the fxns have percentages in them?

Amount is the percent that you are trying to change the color by. If you want to increase by 50% (or .5) you need to multiply by 1.5 (That is 150% of the original color amount Kelly Lyons

I wrote my code the same way as above but I keep getting spacing errors, any idea why?

if your referring to the last code posted....try putting the 3rd line of code as the same indentation as the 2nd line...

def changeColor(pict,amt,color)
for px in getPixels(pict):
if (n==1):
setRed(px, getRed(px)(1+amt))
if (n==2):
setGreen(px, getGreen(px)(1+amt))
if (n==3)
setBlue(px, getBlue(px)(1+amt))

what if the amount you want to change it by is zero (no change)? multiplying by zero will take that color out of the pixel.

i think you need to add
if (amount = 0):
return picture




Link to this Page