 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Final Exam Review Fall 2006: Map Filter
Post your questions here:
the code i wrote has some problems but is the idea of what you were looking for?
def afunction(picture):
show(picture)
p=getPixels(picture)
a=map(func1,p)
b=filter(func1,p)
newred=func2(a,b)
print(b)
h=0
x=0
for y in getPixels(picture):
if a[x]==1:
setRed(newred[h])
h=h+1
x=x+1
show(picture)
def func1(p):
if getRed(p) >99:
return 1
if getRed(p)<100:
return 0
def func2(a,b):
c=0
x=0
for x in a[:]:
if a[x]==1:
b[c]=b[c]+100
c=c+1
return b
def change(pic):
for p in getPixels(pic):
r=filter(amountRed,p)
map(changeRed,p)
def changeRed(p):
setRed(p,getRed2)
def amountRed(p):
if getRed(p) < 100:
return p
I tried this, but it didn't work. Any advice?
Try avoiding the loop in change(pic). You really want to apply map and filter to a list of all of the pixels. You do not want to iterate and apply map and filter over each individual pixel. REMOVEDpe this helps. Larry Olson
def checkRed(pixel):
if getRed(pixel) < 100:
return 1
else:
return 0
def increaseRed(pixel):
value=getRed(pixel)
value=value + 100
setRed (pixel, value)
def main (picture):
alist=filter(checkRed, getPixels(picture)
map(increaseRed, alist)
Student4563
def checkRed(pixel):
if getRed(pixel) < 100:
return pixel
def setNewRed(pixel):
setRed(pixel, getRed(pixel) + 100)
return pixel
def main(picture):
filteredREMOVEDst = filter(checkRed, getPixels(picture))
map(setNewRed, filteredREMOVEDst)
Megan Bowen
Link to this Page