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

Summer2006 Midterm 1 Review: Check your luminance

Questions?

Is this close to correct? For the "between 50 and 200" were we supposed to use>, or should I have used a range?
def checkLuminance(picture):
  for p in getPixels(picture):
    newRed=getRed(p)*0.3
    newGreen=getGreen(p)*0.59
    newBlue=getBlue(p).11
    luminance=newRed+newGreen+newBlue
    setColor(p,makeColor(luminance,luminance,luminance))

def testMe(luminance):
  if (luminance < 10):
    print "That's going to be awfully dark"
  if (luminance >=10 and luminance <= 50):
    print "A little dark"
  if (luminance >50 and luminance < 200):
    print "Looks like a good range"
  if (luminance >= 200 and luminance <250):
    print "Getting kinda bright"
  if (luminance >= 250):
    print "AHHH! MY EYES!"

I forgot the close thingy...I do have indentions.

Almost perfect. You don't need the setColor line. You just need to compute the luminance and you're doing that correctly in the line above. Also, since you're using 2 seperate functions, you need to call the second function from the first by adding 'testMe(luminance)' as your last line to your checkLuminance function. Your 'if' condition for "between 50 and 200" is right. - Bobby Mathew

Since I posted the above, I thought I better show how they did it in recitation. I was taking a picture into the funtion, we were supposed to take in three numbers that represented red,green and blue :
def checkLuminance(redNum,greenNum,blueNum):
  luminance=redNum*.3+ greenNum*.59+blueNum*.11
    
  if (luminance < 10):
    print "That's going to be awfully dark"
  if (luminance >=10 and luminance <= 50):
    print "A little dark"
  if (luminance >=50 and luminance < 200):
    print "Looks like a good range"
  if (luminance >= 200 and luminance <250):
    print "Getting kinda bright"
  if (luminance >= 250):
    print "AHHH! MY EYES!"


Yeah, i missed the part where it said 'takes 3 numbers as parameters'. Thanks for correcting it. _ Bobby Mathew

def checkLuminance(picture):
   for p in getPixels(picture):
   r = getRed(p)*0.3
   g = getGreen(p)*0.59
   b = getBlue(p)*0.11
   luminance = r + g + b

def testMe(luminance):
   if (luminance < 10):
    print "That's going to be awfully dark"
  if (luminance >=10 and luminance <= 50):
    print "A little dark"
  if (luminance >50 and luminance < 200):
    print "Looks like a good range"
  if (luminance >= 200 and luminance <250):
    print "Getting kinda bright"
  if (luminance >= 250):
    print "AHHH! MY EYES!"


def checkLuminance(picture):
for p in getPixels(picture):
r = getRed(p)0.3
g = getGreen(p)0.59
b = getBlue(p)0.11
luminance = r + g + b
testMe(luminance)

def testMe(luminance):
if (luminance 10):
print "That's going to be awfully dark"
if (luminance >=10 and luminance = 50):
print "A little dark"
if (luminance >50 and luminance 200):
print "Looks like a good range"
if (luminance >= 200 and luminance 250):
print "Getting kinda bright"
if (luminance >= 250):
print "AHHH! MY EYES!"


def checkLuminance(picture):
   for p in getPixels(picture):
   r = getRed(p)*0.3
   g = getGreen(p)*0.59
   b = getBlue(p)*0.11
   luminance = r + g + b
   testMe(luminance)

def testMe(luminance):
  if (luminance < 10):
    print "That's going to be awfully dark"
  if (luminance >=10 and luminance <= 50):
    print "A little dark"
  if (luminance >50 and luminance < 200):
    print "Looks like a good range"
  if (luminance >= 200 and luminance <250):
    print "Getting kinda bright"
  if (luminance >= 250):
    print "AHHH! MY EYES!"


You have to take in 3 parameters. Check a few posts above. The right answer is given. - Bobby Mathew



Link to this Page