Fall 2006 Midterm 1 Review: Check your luminance
Questions?
def checkLuminance(picture):
for p in getPixels(picture):
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
luminance = (r*.3 + g*.59 + b.11)
if (luminance < 10):
print "That's going to be awfully dark"
if (luminance >= 10 <= 50):
print "A little dark."
if (luminance > 50 < 200):
print "Looks like a good range."
if (luminance >= 200 < 250):
print "Getting kinda bright."
if (luminance >= 250):
print "AHHH! MY EYES!"
setColor(p,makeColor(luminance,luminance,luminance))
show(picture)
when i run this w/o the ifs it works, but then if i have the ifs it prints out its going to be awfully dark forever can you pls tell me why?
| Most likely because the picture you are passing in has dark pixels at the beginning of it. Why are yoy setting the color towards the end of your code? -Albert d'Heurle |
I did the same thing in the beginning, but this is now what I have and it works:
def checkLuminance (r,g,b):
luminance = r * .3 + g * .59 + b * .11
if (luminance < 10):
print "That's going to be awfully dark"
if (luminance >= 10 <= 50):
print "A little dark."
if (luminance > 50 < 200):
print "Looks like a good range."
if (luminance >= 200 < 250):
print "Getting kinda bright."
if (luminance >= 250):
print "AHHH! MY EYES!"
Stacy Schwaiger
should it go through and say a little dark or getting kinda bright for EVERY pixel?
| What pixels? The function just takes three numbers, representing the r, g, and b values. They could be the r,g,b values for a pixel or the average values for a picture ... or anything. So Stacy's suggestion above looks as though it might be correct, but the very first suggestion, which takes a picture as an argument, can't be. (I think you're suggesting that the first program would be very boring to run, since the messages would be printed for every pixel! And you're right, of course. It's the user, not the program, that would be saying "AHHH! MY EYES!" in that case!) Colin Potts | |
def checkLuminance (r,g,b):
luminance = r * .3 + g * .59 + b * .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!"
I found that when I loaded the above this code, some pretty funny stuff was going on. For example, when I put checkLuminance (100,100,100), the print was "A little dark" AND "looks like a good range" But, it can't be both, and what's happened with the first code is the computer's getting confused because she didn't put "and luminance". So, putting "and luminance" solves it.
Leah McClellan
Can anybody see why this is not working for me? What should I type in the command area?
def checkLuminance(r,g,b):
for p in getPixels(pic):
r=getRed(p)
g=getGreen(p)
b=getBlue(p)
luminance=r*.3+g*.59+b*.11
if (luminance < 10):
print "That's going to be awfully dark"
if (luminance >= 10 or 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!"
charlie Blackmon
| Charlie, forget the picture and the pixels in it. There is no picture. The function just takes three numbers: a red value, r, a green value, g, and a blue value, b and tells you whether that combination of color values is bright, dark, or whatever. Your command line call – once you correct the function – will be something like "checkLuminance(10,100,50) Colin Potts |
def checkLuminance(r,b,g,):
luminance = r*.3 + g*.59 +b*.11
if(luminance <10):
print luminance
print "That's going to be awfully dark"
if(luminance >=10 and luminance<=50):
print luminance
print "A little dark."
if(luminance >50 and luminance<200):
print luminance
print "Looks like a good range"
if(luminance >=200 and luminance<250):
print luminance
print "Getting kinda bright"
if(luminance >=250):
print luminance
print "Ahh! MY EYES!"
Everything seems to work fine for me, plus we also need to print the luminance values too, not just the words describing it.
Should the second parameter be "Greater than or equal to 10 AND less than or equal to 50" instead of "Greater than or equal to 10 OR less than or equal to 50?" The "or" is what's causing "A little dark" to appear for nearly every luminance.
Courteney Ross
you're right, because every real number is either "less or equal to 10" OR "greater or equal to 50"... but only the numbers from 10 to 50 are "greater than or equal to 10 AANNDD less than or equal to 50." these are the values he intended to have the code look for.
Link to this Page