Sie sind auf Seite 1von 9

Rose Colored Lenses

This program takes a


def roseColoredGlasses():
normal picture and turns
filename = pickAFile()
in to a rose colored one. It
pic = makePicture(filename)
took a little bit to get the
pixels = getPixels(pic)
color to be what I would
for p in pixels:
consider rose but overall
r = getRed(p)
it was not a very difficult
setRed(p, r * 1.5)
problem.
f = getGreen(p)
setGreen(p, f * .75)
y = getBlue(p)
setBlue(p, y * .75)
repaint(pic)
Negative

This program will take any def makeNegative():


picture and switch the filename = pickAFile()
color values to their pic =
opposite numbers. To do makePicture(filename)
this it just took a little bit of pixels = getPixels(pic)
math and color for p in pixels:
manipulation to achieve r = getRed(p)
this but looks great. setRed(p, (255 - r))
f = getGreen(p)
setGreen(p, (255 - f))
y = getBlue(p)
setBlue(p, (255 - y))
repaint(pic)
Black and White

def BnW():
This program will take filename = pickAFile()
any colored, or even non pic =
colored, picture and turn makePicture(filename)
it into a black and white pixels = getPixels(pic)
picture by scaling all of for p in pixels:
the colors to a like pallet. r = getRed(p)
g = getGreen(p)
b = getBlue(p)
scale = ((r + g + b)/3)
setRed(p, scale)
setBlue(p, scale)
setGreen(p, scale)
repaint(pic)
Bottom-to-Top Mirror

This program will take def bottomTopMirror(picture):


a picture and put the width = getWidth(picture)
bottom half of the height = getHeight(picture)
picture onto the top
half. The tricky part for y in range(0, height - 1):
about this program for x in range(0, width - 1):
was the make the top sourcePixel = getPixel(picture,
half come out of the x, height - y - 1)
bottom half and not targetPixel = getPixel(picture, x
just have another ,y)
copy of the bottom color = getColor(sourcePixel)
half sitting on top. setColor(targetPixel, color)

repaint(picture)
Collage
This lab I
incorporated a little
bit of each of the
previous labs into it.
However, for some
reason whenever I
would save this file it
would change the
overall color to a
redder color.

def collage(source, target, targetX, targetY):

sourcePic = makePicture(source)
targetPic = makePicture(target)
sourceWidth = getWidth(sourcePic)
sourceHeight = getHeight(sourcePic)
targetWidth = getWidth(targetPic)
targetHeight = getHeight(targetPic)

for x in range (0, sourceWidth):


for y in range (0, sourceHeight):
px = getPixel(sourcePic, x , y)
pxSize = getPixel(targetPic, (x + targetX), (y + targetY))
copyColor = getColor(px)
setColor(pxSize, copyColor)
repaint(targetPic)
writePictureTo(targetPic, pickAFile())
Art-i-fy
def Artify():
filename = pickAFile()
pic = makePicture(filename)
pixels = getPixels(pic)
for x in pixels:
r = getRed(x)
g = getGreen(x)
b = getBlue(x)
if r < 64:
setRed(x, 31)
elif r > 63 and r < 128:
setRed(x, 95)
elif r > 127 and r < 192:
setRed(x, 159)
else:
setRed(x, 223)
if g < 64:
setGreen(x, 31)
elif g > 63 and g < 128:
This program makes a picture setGreen(x, 95)
look more arty. It makes all of elif g > 127 and g < 192:
the colors a little softer and setGreen(x, 159)
gives the look of something else:
that has been painted setGreen(x, 223)
if b < 64:
setBlue(x, 31)
elif b > 63 and b < 128:
setBlue(x, 95)
elif b > 127 and b < 192:
setBlue(x, 159)
else:
setBlue(x, 223)
repaint(pic)
Green Screen

def setBorder(greenScreen,
background):

gscreen=makePicture(greenScree
This is actually a part of our
n)
St. Patricks day card but it
uses the green screen
background=makePicture(backgro
effect to add the border to
und)
the picture. Since the
pg=getPixels(gscreen)
overall picture is rather
pb=getPixels(background)
green already we ended up
gsc=makeColor(255,0,255)
making it more of a fusha
for p in pg:
screen to avoid unwanted
color = getColor(p)
alterations.
dist=distance(color,gsc)
if dist < 170:

np=getPixelAt(background,getX(p)
,getY(p))
setColor(p,getColor(np))
show(gscreen)
This is my groups St. Patricks day greeting card. I do not have
the file for the leprechaun that we used so this one is a little out
of scale, but it brings together several elements in a nice
greeting card.

Das könnte Ihnen auch gefallen