Você está na página 1de 6

#Midterm Project

#pic1 size must be smaller than pic2 size

def blend(pic1,pic2):

width = getWidth(pic1)

height = getHeight(pic1)

blendPic = makeEmptyPicture(width,height)

#loop through pixels

for y in xrange(height):

for x in xrange(width):

#get pixel from blend

targetPx = getPixel(blendPic, x, y)

#get pixels

px1 = getPixel(pic1, x , y)

px2 = getPixel(pic2, x , y)

#average rgb between pixels

r1, g1, b1 = getRed(px1), getGreen(px1), getBlue(px1)

r2, g2, b2 = getRed(px2), getGreen(px2), getBlue(px2)

#blur color

blendColor = makeColor( (r1+r2)/2, (g1+g2)/2, (b1+b2)/2 )

setColor(targetPx, blendColor)

#show(blendPic)

return blendPic

#paints otter green on bottom half of image

def thirdGreen(pic):

for x in range(0, getWidth(pic)):


for y in range(2*getHeight(pic)/3,getHeight(pic)):

p = getPixel(pic,x,y)

color = makeColor(57,100,90)

setColor(p,color)

return(pic)

#paints otter green on bottom half of image

def thirdBlue(pic):

for x in range(0, getWidth(pic)):

for y in range(getHeight(pic)/3,2*getHeight(pic)/3):

p = getPixel(pic,x,y)

color = makeColor(0,42,78)

setColor(p,color)

return(pic)

#paints otter green on top half of image

def thirdSand(pic):

for x in range(0, getWidth(pic)):

for y in range(0,getHeight(pic)/3):

p = getPixel(pic,x,y)

color = makeColor(147,127,85)

setColor(p,color)

return(pic)
def makeBlank():

return makeEmptyPicture(450,450)

def CSUMBy(picture):

canvas = makeBlank()

path = "C:\Python\photoSm.png"

pic1 = makePicture(path)

#for testing on a photo of myself

#pic2 = makePicture("C:\Python\me.jpg")

pic2 = picture

#blend otter and picture

pic3 = blend(pic1,pic2)

#send to green

pic4 = thirdGreen(canvas)

#send to blue half

pic5 = thirdBlue(canvas)

pic6 = thirdSand(canvas)

canvas = blend(pic3,pic6)

show(canvas)

writePictureTo(canvas, "C://python//csumby.jpg")

# This function gets a picture from file

def get_pic():

return makePicture(pickAFile())

#This function creates a Matrix feel to an image that is 1280 X 720 or smaller

def matrixify(picture):
pic1 = picture

pic2 = makePicture("D://Downloads//School//CST 205//Midterm Project//matrix-code.jpg")

pic = lineDwg(pic1)

blended = blend(pic, pic2)

blended = makeGreen(blended)

show(blended)

writePictureTo(blended, "D://Downloads//School//CST 205//Midterm Project//matrixify.jpg")

#This function creates a green line drawing of the outline of an image and applies it to a black
background

def lineDwg(pic):

#turn B&W

pic = betterBnW(pic)

picture = duplicatePicture(pic)

width, height = getWidth(pic) , getHeight(pic)

for y in xrange(height - 1):

for x in xrange(width - 1):

px = getPixel(picture, x, y) # original pixel

right = getPixel(picture, x + 1, y)#right pixel

below = getPixel(picture, x, y + 1)#below pixel

g = getGreen(px)

#get luminance

luminance = lambda px: (getRed(px) + getBlue(px) + getGreen(px) )/3

LR = luminance(right)#luminance to right pizel


LB = luminance(below)#luminance below pixel

LO = luminance(px)#luminance of original pixel

#pixel edge

if abs(LR - LO) > 1 and abs(LB - LO) > 1:

#return b&w image

setRed(px, 0)

setGreen(px, g * .8)

setBlue(px, 0)

else:

setColor(px, black)

return picture

# This function makes a more suitable black and white picture

def betterBnW(picture):

pic = picture

pixels = getPixels(pic)

for p in pixels:

r = getRed(p)

g = getGreen(p)

b = getBlue(p)

luminace = ((r * .299) + (g * .587) + (b * .114))

setRed(p, luminace)

setGreen(p, luminace)

setBlue(p, luminace)

return (pic)

# This function makes the picture have an green hue


def makeGreen(picture):

pic = picture

pixels = getPixels(pic)

for p in pixels:

g = getGreen(p)

setRed(p, 0)

setGreen(p, g * .8)

setBlue(p, 0)

repaint (pic)

return pic

Você também pode gostar