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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

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??


mmhmm. -Blake O'Hare

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