Sunteți pe pagina 1din 7

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

tx = targetX
for x in range(0, getWidth(source)):
ty = targetY
for y in range(0, getHeight(source)):
sourcePix = getPixel(source, x, y)
color = getColor(sourcePix)
targetPix = getPixel(target, tx, ty)
setColor(targetPix, color)
ty = ty + 1
tx = tx + 1

def makeCollage():
width=1500
height=1655
collage = makeEmptyPicture(width, height)

#otter picture
otter = makePicture(getMediaPath("otter.jpg"))
a=shrink(otter)
small_otter=shrink(a)
tiny_otter=shrink(small_otter)
tiny_otter_width = getWidth(tiny_otter)
tiny_otter_height = getHeight(tiny_otter)
#upper row of otters
x=0
while(x < width - tiny_otter_width):
pyCopy(tiny_otter, collage, x, 1)
x = x + tiny_otter_width
x1 = x - (tiny_otter_width - (width - x))
pyCopy(tiny_otter, collage,x1, 1)
#left vertical row of otters
y = tiny_otter_height
while(y < height - tiny_otter_height):
pyCopy(tiny_otter, collage, 0, y)
y = y + tiny_otter_height
y1 = y - (tiny_otter_height - (height - y))
pyCopy(tiny_otter, collage,0, y1)
#bottom row of otters
z = tiny_otter_width
while (z < width - tiny_otter_width):
pyCopy(tiny_otter, collage, z, height - tiny_otter_height)
z = z + tiny_otter_width
z1 = z - (tiny_otter_width - (width - z))
pyCopy(tiny_otter, collage, z1, height - tiny_otter_height)
#vertical right row of otters
t = tiny_otter_height
while(t< height -tiny_otter_height):
pyCopy(tiny_otter, collage,width-tiny_otter_width, t)
t = t + tiny_otter_height
t1 = t - tiny_otter_height
pyCopy(tiny_otter, collage, width-tiny_otter_width, t1)

#python picture
python = makePicture(getMediaPath("python.jpg"))
quadruple_mirror(python)
python_width = getWidth(python)
python_height = getHeight(python)
pyCopy(python, collage, tiny_otter_width, tiny_otter_height)

#waterfall picture
waterfall = makePicture(getMediaPath("water_smaller.jpg"))
bottom_to_top_mirror(waterfall)
waterfall_height = getHeight(waterfall)
colX = tiny_otter_width + python_width
pyCopy(waterfall, collage, colX, tiny_otter_height)

#my dog1
pic1 = makePicture(getMediaPath("dog.jpeg"))
dog = shrink(pic1)
vertical_mirror(dog)
dog_width = getWidth(dog)
dog_height = getHeight(dog)
coordX = width - tiny_otter_width - dog_width
pyCopy(dog, collage, coordX, tiny_otter_height)

#my dog1
dog1 = makePicture(getMediaPath("dog1.jpeg"))
betterBnW(dog1)
dog1_height = getHeight(dog1)
dog1_width = getWidth(dog1)
dog2X = width - tiny_otter_width - dog1_width
dog2Y = tiny_otter_height + dog_height
pyCopy(dog1, collage, dog2X, dog2Y)

#my dog4
dog4 = makePicture(getMediaPath("dog4.jpg"))
roseColoredGlasses(dog4)
dog4_width = getWidth(dog4)
dog4X = width - tiny_otter_width - dog4_width
dog4Y = tiny_otter_height + dog_height + dog1_height
pyCopy(dog4, collage, dog4X, dog4Y)

#my dog5
dog5 = makePicture(getMediaPath("dog5.jpg"))
noBlue(dog5)
dog5_height = getHeight(dog5)
hght = tiny_otter_height + python_height
pyCopy(dog5, collage, tiny_otter_width, hght)

#my dog2
dog2 = makePicture(getMediaPath("dog2.jpg"))
p1=shrink(dog2)
p2=shrink(p1)
dog2_small=shrink(p2)
makeNegative(dog2_small)
dog2_small_width = getWidth(dog2_small)
dog2_small_height = getHeight(dog2_small)
dog2_smallY = tiny_otter_height + python_height + dog5_height
pyCopy(dog2_small, collage, tiny_otter_width, dog2_smallY)

#my dog6
pic5 = makePicture(getMediaPath("dog1.jpeg"))
horizontal_mirror(pic5)
pic5X = tiny_otter_width + dog2_small_width
pic5Y = tiny_otter_height + waterfall_height
pyCopy(pic5, collage, pic5X, pic5Y)

#python
pic9 = makePicture(getMediaPath("python.jpg"))
bottom_to_top_mirror(pic9)
pic9Y = tiny_otter_height + python_height + dog5_height + dog2_small_height
pyCopy(pic9, collage, tiny_otter_width, pic9Y)

#three small otters column


n=0
y_coord = tiny_otter_height + waterfall_height
x_coord = tiny_otter_width + dog2_small_width + getWidth(pic5)
while(n<3):
pyCopy(small_otter, collage, x_coord, y_coord)
y_coord = y_coord + getHeight(small_otter)
n=n+1

#my dog7
dog7 = makePicture(getMediaPath("dog7.jpg"))
dog7_width = getWidth(dog7)
dog7_height = getHeight(dog7)
dog7Y = height - tiny_otter_height - dog7_height
pyCopy(dog7, collage, tiny_otter_width , dog7Y)

pic3=makePicture(getMediaPath("dog8.jpg"))
dog8=rotatePic(pic3)
sepiaTone(dog8)
dog8Y=height-tiny_otter_height-getHeight(dog8)
dog8X=tiny_otter_width+dog7_width
pyCopy(dog8, collage, dog8X, dog8Y)
#one small otter
yb = tiny_otter_height + getHeight(waterfall)+ getHeight(pic5)
xb = tiny_otter_width + getWidth(dog8) + dog7_width
pyCopy(small_otter, collage, xb, yb)

show(collage)
writePictureTo(collage, "collage.jpg")
return collage

#Rose picture
def roseColoredGlasses(pic):
pixels = getPixels(pic)
pinkRed = 255
pinkGreen = 105
pinkBlue = 180
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
setRed(p, 0.3*pinkRed + 0.7*r)
setGreen(p, 0.3*pinkGreen + 0.7*g)
setBlue(p, 0.3*pinkBlue + 0.7*b)
return pic

#Remove blue from picture


def noBlue(pic):
pixels = getPixels(pic)
for p in pixels:
setBlue(p, 0)
return pic

#Black and white


def betterBnW(pic):
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
luminance = r*0.299 + g*0.587 + b*0.114
setColor(p, makeColor(luminance, luminance, luminance))
return pic

#Negative picture
def makeNegative(pic):
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
setRed(p, 255 - r)
setGreen(p, 255 - g)
setBlue(p, 255 - b)
return pic

#Vertical mirror
def vertical_mirror(pic):
full_width = getWidth(pic)
width = getWidth(pic)/2
height = getHeight(pic)
for x in range(0, width):
for y in range(0, height):
pix = getPixel(pic, x, y)
color = getColor(pix)
pixToChange = getPixel(pic, full_width-x-1 , y)
setColor(pixToChange, color)
return pic

#Horizontal mirror
def horizontal_mirror(pic):
full_height = getHeight(pic)
height = getHeight(pic)/2
width = getWidth(pic)
for x in range(0, width):
for y in range(0, height):
pix = getPixel(pic, x, y)
color = getColor(pix)
pixToChange = getPixel(pic, x, full_height-y-1)
setColor(pixToChange, color)
return pic

#Bottom-to-top mirror
def bottom_to_top_mirror(pic):
full_height = getHeight(pic)
height = getHeight(pic)/2
width = getWidth(pic)
for x in range(0, width):
for y in range(full_height-1, height, -1):
pix = getPixel(pic, x, y)
color = getColor(pix)
pixToChange = getPixel(pic, x, full_height-y)
setColor(pixToChange, color)
return pic

#Quadruple mirror
def quadruple_mirror(pic):
full_width = getWidth(pic)
width = getWidth(pic)/2
height = getHeight(pic)
for x in range(0, width):
for y in range(0, height):
pix = getPixel(pic, x, y)
color = getColor(pix)
pixToChange = getPixel(pic, full_width-x-1 , y)
setColor(pixToChange, color)

full_height = getHeight(pic)
height = getHeight(pic)/2
width = getWidth(pic)
for x in range(0, width):
for y in range(0, height):
pix = getPixel(pic, x, y)
color = getColor(pix)
pixToChange = getPixel(pic, x, full_height-y-1)
setColor(pixToChange, color)
return pic

#Rotate picture in 90 degree left


def rotatePic(pic):
mypic = makeEmptyPicture(getHeight(pic), getWidth(pic))
for x in range(0, getWidth(pic)):
for y in range(0, getHeight(pic)):
pix = getPixel(pic, x, y)
color = getColor(pix)
setColor(getPixel(mypic, getY(pix), getX(pix)), color)
return mypic

#Make picture twice smaller


def shrink(pic):
mypic = makeEmptyPicture(getWidth(pic)/2, getHeight(pic)/2)
mypicX = 0
mypicY = 0
for x in range(0, getWidth(pic)-1, 2):
for y in range(0, getHeight(pic)-1, 2):
pix = getPixel(pic, x, y)
color = getColor(pix)
setColor(getPixel(mypic, mypicX, mypicY), color)
mypicY= mypicY+1
mypicX = mypicX+1
mypicY = 0
return mypic

#Sepia
def sepiaTone(pic):
betterBnW(pic)
for p in getPixels(pic):
r = getRed(p)
b = getBlue(p)
if (r < 63):
r = r*1.1
b = b * 0.9
elif ( r > 62 and r <192):
r = r*1.15
b= b * 0.85
elif ( r > 191):
r= r*1.08
if(r>255):
r = 255
b= b*0.93
setRed(p, r)
setBlue(p, b)
return(pic)

S-ar putea să vă placă și