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 Fall 2004: If red were green were red

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

Back to Fall2004 Midterm 1 Review


def redGreenOut():
  file = pickAFile()
  pic = makePicture(file)
  show(pic)
  for x in getPixels(pic):
    r = getRed(x)
    b = getBlue(x)
    g = getGreen(x)
    n = (r+g)/2
    q = makeColor(n,b,n)
    setColor(x,q)
  repaint(pic)
  show(pic)


is that better?

Albert, try posting the code as in the FAQ so that we can figure out which is code and which are statements. From what's here, I can see that you're not actually answering the question correctly. (Hint: Consider inputs.) Mark Guzdial

Also, are we using a RGB or an RBG color scheme?? Kelly Lyons



If you averaged out the red and green pixels for an image wouldn't you be left with a blue/grey/yellow picture?

Try it and tell us. Better yet, post your result and show us. Mark Guzdial


Try doing it in JES to different pictures and see. Kelly Lyons

def redGreenOut(pic):
for px in getPixels(pic):
red=getRed(px)
green=getGreen(px)
mix=(red+green)/2
newcolor=setColor(px, makeColor(mix,mix,blue))


Close. Where do you define blue? Kelly Lyons

yeah...i think this one is better:
def redGreenOut(pic):
for px in getPixels(pic):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
mix=(red+green)/2
newcolor=setColor(px, makeColor(mix,mix,blue))

Looks pretty good, but why are you creating the variable newcolor in the last line. True, it does not cause an error, but do you really need it? Kelly Lyons

def redGreenOut(pic):
for px in getPixels(pic):
r=getRed(px)
b=getBlue(px)
g=getGreen(px)
rg=(r+g)/2
color=makeColor(rg,b,rg)
setColor(px,color)
show(pic)

I just remembered that the color order is rgb. That means that color=makeColor aught to be (rg,rg,b) instead of (rg,b,rg) right?
Right Kelly Lyons

def redGreenOut(pic):
for p in getPixels(pic):
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
x = (r+g)/2
colorBlind = makeColor(x,x,b)
setColor(p, colorBlind)
show(pic)


def redGreenOut2(pig):
pigf=getMediaPath("pig.jpg")
pig=makePicture(pigf)
for p in getPixels(pig):
newRed = getRed(p)
newGreen = getRed(p)
newBlue = getBlue(p)
luminance = (newRed+newGreen)/2
setColor(p,makeColor(luminance,luminance,newBlue))
show(pig)

Your function takes input, i.e. a picture, so why are you making a picture inside the function (on your first two lines) Kelly Lyons

def redGreenOut(picture):
for px in getPixels(picture):
red = getRed(px)
green = getGreen(px)
setRed(px, (red+green)/2)
setGreen(px, (red+green)/2)
show(picture)

ok - i now know that i cant use red and green as variables - change those to r and g instead


how do i post my picture to see if i am writing the program correctly? thanks.

does this picture look right? Uploaded Image: MTQ1.jpg

def redGreenOut(picture):
for px in getPixels(picture):
r = getRed(px)
g = getGreen(px)
colorBlind = (r+g)/2
setRed(px, colorBlind)
setGreen(px, colorBlind)

Stephanie Chester

My code looks like this. Am I doing something wrong?
It works alright.

def redGreenOut(picture):
  for p in getPixels(picture):
    average=(getRed(p)+getGreen(p))/2
    blue=getBlue(p)
    setColor(p,makeColor(average,average,blue))




QUESTION: if you have some process(x, y) with x and y being whatever, like values or colors, does it take the original x and make it what you defined y as?

It depends what process you are talking about. But, for instance, in the case of setColor(x, y), x will be the original pixel value, and then y is the new value that you will be changing x to. Summer McWilliams

It depends on what your process(x,y) did inside it's function. It won't automatically make the x = y unless somewhere in the code, you had a line that said x = y, and then for the remainder of the function x would be equal to y. Does this answer your question, or I am completely missing what you're getting at? Kelly Lyons

def redGreenOut():
file=pickAFile()
pic=makePicture(file)
for px in getPixels(pic):
r=getRed(px)
g=getGreen(px)
b=getBlue(px)
rg=(r+g)/2
color=makeColor(rg,rg,b)
setColor(px,color)
show(pic)

Is this right?
No, your function is supposed to be taking input Kelly Lyons

Is it right?

def redGreenOut():
picture = makePicture(pickAFile())

for px in getPixels(picture):
r=getRed(px)
g=getGreen(px)
b=getBlue(px)
average=(r+g)/2
setColor(px, makeColor(average, average, b))

show(picture)

Your function is supposed to be taking input, not creating the picture inside the function Kelly Lyons

def redGreenOut():
file=pickAFile()
picture=makePicture(file)
show(picture)

for p in getPixels(picture):
r=getRed(p)
g=getGreen(p)
setRed(p,((r+g)/2))
setGreen(p,((r+g)/2))
repaint(picture)

Your function is supposed to take input, not create a picture inside your function Kelly Lyons

When do you know when you need to show the picture in the answer?
When the specifications say for the function to show the picture Kelly Lyons

Guys, check this out–

def redGreenOut(pic):
for pixels in getPixels(pic):
r=getRed(pixels)
g=getGreen(pixels)
newColor=(r + g) / 2
setRed(pixels, newColor)
setGreen(pixels, newColor)

I do not know if there is anything wrong with this answer. However, I do wanna know whether one has to have r, g, and b all included everytime he or she codes for a picture because this answer does not have the blue value included in it, which I don't think I ever need to include the blue in it.
Yes, you are right. You never have to use the blue value at all in writing the code the way your wrote it. Kelly Lyons

Oops, I am sorry, I did the indentation wrong. Somebody please try to fix it, thanx!

Do you have to include repaint() in the function?


Uploaded Image: MTQ1.jpg
Uploaded Image: redGreenOut.jpg.jpg

Link to this Page