def blendPictures(pict1, pict2, overlapAmt):
width1 = getWidth(pict1)
height1 = getHeight(pict1)
width2 = getWidth(pict2)
height2 = getHeight(pict2)
newWidth = width1 + width2 - overlapAmt
newHeight = min(height1, height2)
newCanvas = makeEmptyPicture(newWidth, newHeight)
for x in range(width1 - overlapAmt):
for y in range(newHeight):
color = getColor(getPixel(pict1, x, y))
setColor(getPixel(newCanvas, x, y), color)
pict2_x = 0
for pict1_x in range(width1 - overlapAmt, width1):
for y in range(newHeight):
pixel1 = getPixel(pict1, pict1_x, y)
pixel2 = getPixel(pict2, pict2_x, y)
newRed = 0.50 * getRed(pixel1) + 0.50 * getRed(pixel2)
newGreen = 0.50 * getGreen(pixel1) + 0.50 * getGreen(pixel2)
newBlue = 0.50 * getBlue(pixel1) + 0.50 * getBlue(pixel2)
color = makeColor(newRed, newGreen, newBlue)
setColor(getPixel(newCanvas, pict1_x, y), color)
pict2_x = pict2_x + 1
targetX = width1
for x in range(overlapAmt, width2):
for y in range(newHeight):
color = getColor(getPixel(pict2, x, y))
setColor(getPixel(newCanvas, targetX, y), color)
targetX = targetX + 1
return newCanvas
def swapBackground( src, background, newBackground ):
# src, and background must be the same size
# newBackground must be at least as big as src and background
for x in range(1, getWidth( src ) + 1 ) :
for y in range(1, getHeight( src ) + 1 ) :
srcPxl = getPixel( src, x, y )
backgroundPxl = getPixel( background, x, y )
if (distance(getColor( srcPxl ), getColor( backgroundPxl )) < 15.0):
setColor( srcPxl, getColor( getPixel( newBackground, x, y ) ) )
return src
jackalope = blendPictures('rabbit.jpg', 'antelope.jpg', 50)
writePictureTo(jackalope, "./jackalope.jpg")
#here swap the background to place your photo on front
swapBackground( 'photograph.jpg', 'jackalope.jpg', newBackground )
writePictureTo(newBackground, "./nexttojackalope.jpg")
swapBackground( 'rabbit.jpg', 'campus.jpg', newBackground1 )
writePictureTo(newBackground1, "./campustemp.jpg")
swapBackground( 'antelope.jpg', 'campustemp.jpg', newBackground2 )
writePictureTo(newBackground1, "./campusfinal.jpg")
Where the .jpg's are I put where the files will go or where they are pulling from. I have a picture of a rabbit and an antelope with a jackalope wav file and a picture of myself and a picture to put as the background. But I still get an error on line 2 saying that getWidth(picture) isn't defined and I'm not sure what to do. Any ideas?
In order to use the
getWidth()
function you need to pass a picture object as it's argument. So you will need to first create a picture object using themakePicture()
function. For example:Here's a good guide on working with pictures in JES. http://www.cs.bu.edu/courses/cs101b1/jes/#Pictures%20and%20Sound