# Collage Picture Program - for Beginning Programming July 2009 # Mr. Michaud # www.nebomusic.net # Load and Run. Select Pictures that are the same dimensions. #------------- Functions -----------------# # Pick and Make Picture Function def pickAndMakePicture(): # Picture Chooser Pic1 = pickAFile() Pic1 = makePicture(Pic1) return Pic1 # Gray Scale Picture def grayScale(pict): for p in getPixels(pict): intensity = (getRed(p)+getGreen(p)+getBlue(p))/3 setColor(p, makeColor(intensity, intensity, intensity)) return pict def negative(picture): # Creates a negative of the picture for px in getPixels(picture): red = getRed(px) green = getGreen(px) blue = getBlue(px) negColor = makeColor(255-red, 255-green, 255-blue) setColor(px, negColor) return picture # Reverse Negative Picture 3, 1 def reverseNegative(Pic1, pic): startPoint = (getWidth(Pic1) * 2) + 1 endPoint = startPoint + getWidth(Pic1) endY = getHeight(Pic1) for x in range(startPoint, endPoint): for y in range(1, endY): px = getPixel(pic, x, y) red = getRed(px) green = getGreen(px) blue = getBlue(px) negColor = makeColor(255-red, 255-green, 255-blue) setColor(px, negColor) return pic # Reverse Negative Picture 2, 2 def reverseNegative1(Pic1, pic): startPoint = getWidth(Pic1) + 1 endPoint = startPoint + getWidth(Pic1) startY = getHeight(Pic1) + 1 endY = getHeight(pic) for x in range(startPoint, endPoint): for y in range(startY, endY): px = getPixel(pic, x, y) red = getRed(px) green = getGreen(px) blue = getBlue(px) negColor = makeColor(255-red, 255-green, 255-blue) setColor(px, negColor) return pic # Mirror Vertical def mirrorVertical(pic): mirrorPoint = getWidth(pic) / 2 width = getWidth(pic) for y in range(1, getHeight(pic)): for x in range(1, mirrorPoint): leftPixel = getPixel(pic, x, y) rightPixel = getPixel(pic, width - x, y) color = getColor(leftPixel) setColor(rightPixel, color) return pic # Mirror Top to Bottom def mirrorHorizontal(pic): mirrorPoint = getHeight(pic) / 2 Height = getHeight(pic) for x in range (1, getWidth(pic)): for y in range (1, mirrorPoint): topPixel = getPixel(pic, x, y) bottomPixel = getPixel(pic, x, Height - y) color = getColor(topPixel) setColor(bottomPixel, color) return pic # Mirror Diagnal def mirrorDiag(pic): for i in range(1, getWidth(pic)): for x in range(i, getWidth(pic)): y = i Pix = getPixel(pic, x, y) diagPix = getPixel(pic, i, x) color = getColor(Pix) setColor(diagPix, color) return pic def makeCollage(pic1, pic2): # Make a canvas large enough to hold both pictures canvas = makeEmptyPicture(getWidth(pic1) + getWidth(pic2), getHeight(pic1)) # Lay in the first picture targetX = 1 for sourceX in range(1, getWidth(pic1)): targetY = 1 targetX = targetX + 1 for sourceY in range(1, getHeight(pic1)): color = getColor(getPixel(pic1, sourceX, sourceY)) targetPix = getPixel(canvas, targetX, targetY) setColor(targetPix, color) targetY = targetY + 1 # Lay in the second picture targetX = getWidth(pic1) for sourceX in range(1, getWidth(pic2)): targetY = 1 targetX = targetX + 1 for sourceY in range(1, getHeight(pic2)): color = getColor(getPixel(pic2, sourceX, sourceY)) targetPix = getPixel(canvas, targetX, targetY) setColor(targetPix, color) targetY = targetY + 1 return canvas # General Copy Function def copy(source, target, targX, targY): targetX = targX for sourceX in range(1, getWidth(source)): targetY = targY for sourceY in range(1, getHeight(source)): px = getPixel(source, sourceX, sourceY) tx = getPixel(target, targetX, targetY) setColor(tx, getColor(px)) targetY = targetY + 1 targetX = targetX + 1 # Mirror entire Picture Vertical def mirrorEntireVertical(pic): canvas = makeEmptyPicture(getWidth(pic)*2, getHeight(pic)) copy(pic, canvas, 1, 1) mirrorVertical(canvas) return canvas # Mirror entire Picture Horizontal def mirrorEntireHorizontal(pic): canvas = makeEmptyPicture(getWidth(pic), getHeight(pic)*2) copy(pic, canvas, 1, 1) mirrorHorizontal(canvas) return canvas # Final Collage method def finalRender(): Pic1 = pickAndMakePicture() Pic2 = pickAndMakePicture() if getHeight(Pic1) == getHeight(Pic2) and getWidth(Pic1) == getWidth(Pic2): Pic3 = negative(Pic2) canvas = makeCollage(Pic1, Pic3) canvas2 = mirrorEntireHorizontal(canvas) canvas3 = mirrorEntireVertical(canvas2) canvas3 = reverseNegative(Pic1, canvas3) canvas3 = reverseNegative1(Pic1, canvas3) show(canvas3) return canvas3 else: showInformation("You need to select pictures that\nhave the same dimension.") finalRender() #---------Define Main Method----------# # Main Method def main(): showInformation("Select two pictures\nthat have the same\nlength and width.") collage = finalRender() #-------------------------------------# # Run program # main()