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

Spring 2006 Midterm 1 Review - Color-blind

Spring 2006 Midterm 1 Review - Color-blind

is this the right answer?

def redGreenOut(picture):
for p in getPixels(picture):
value=getRed(p)
setRed(p, (getRed(p)+getGreen(p))/2)
value=getGreen(p)
setGreen(p, (getRed(p)+getGreen(p))/2)



Not quite. Trace through your program and see what it is actually doing. -Blake O'Hare

"setGreen(p, (getRed(p)+getGreen(p))/2)"

the problem is, when "getRed" happens the 2nd time it is taking a vlaue that has already been changed.

try this:

def redGreenOut():
  pic = makePicture(pickAFile())
  for p in getPixels(pic):
    avg = (getRed(p) + getGreen(p)) / 2
    setRed(p, avg)
    setGreen(p, avg)
  show(pic)
  repaint(pic)


sorry, i put pickAFile in my code :)


def redGreenOut(picture):
  for p in getPixels(picture):
    pxColor = getColor(p)
    ored = getRed(p)
    oblue = getBlue(p)
    ogreen = getGreen(p)  
    average = (ored + ogreen)*.5
    setRed = (p,average)
    setGreen = (p,average)
  show(picture)
  repaint(picture) 



that was mine above, it doesn't make a change to the picture!
Are you sure it doesn't change the picture? You have show and repaint right next to each other, so it doesn't LOOK like anything has changed, but know what your original picture looked like! You chould move show to before your for loop so you could see the original one before it's changed. Amanda Bennett

this version works also
def redGreenOut(picture):
  for p in getPixels(picture):
    r=getRed(p)
    g=getGreen(p)
    setRed(p,(r+g)/2)
    setGreen(p,(r+g)/2)

Good. Amanda Bennett

Is it necessary to include "show" and "repaint" in the code? And what does "repaint" actually do?

No, you don't need to include in the modifying code. (It's really the job of the function that calls this function to do make the picture and show it.) The JES functions show() and repaint() are discussed in the book on pages 46 and 48, respectively. The difference between them isn't very important and I think on Windows and the Mac, you can get by by just using show(). There should be no need to call both, one after another. Note that repaint() will only show changes to a picture that is already being shown, so if you make a picture and then repaint it, you won't see anything. But if you show it, change it, and then repaint it, you should see the changes. Colin Potts



Link to this Page