Code for transforming pictures
# A template function for transforming pictures
def transformPicture(pic):
allThePixels = getPixels(pic)
for currentPixel in allThePixels:
# Do something to currentPixel by replacing line below with something useful
pass
# This is the above template with the "pass" replaced by a block of three lines
# that darken the current pixel
def darken(pic):
allThePixels = getPixels(pic)
for currentPixel in allThePixels:
setRed(currentPixel, getRed(currentPixel)/2)
setGreen(currentPixel, getGreen(currentPixel)/2)
setBlue(currentPixel, getBlue(currentPixel)/2)
# This is the above template with the "pass" replaced by a block of three lines
# flip the values of the current pixel to make a photographic negative
def negate(pic):
allThePixels = getPixels(pic)
for currentPixel in allThePixels:
# Do something to currentPixel
setRed(currentPixel, 255-getRed(currentPixel))
setGreen(currentPixel, 255-getGreen(currentPixel))
setBlue(currentPixel, 255-getBlue(currentPixel))
Links to this Page