Skip to content

Instantly share code, notes, and snippets.

@gtke
Created March 13, 2013 02:40
Show Gist options
  • Select an option

  • Save gtke/5148971 to your computer and use it in GitHub Desktop.

Select an option

Save gtke/5148971 to your computer and use it in GitHub Desktop.
from Myro import *
def collageMaker(fileName, files, newFileName):
picList = []
for myNum in range(files+1):
newPic = makePicture("{}.jpg".format(myNum))
newRedSum = 0
newGreenSum = 0
newBlueSum = 0
for newPixel in getPixels(newPic):
newRed = getRed(newPixel)
newRedSum += newRed
newGreen = getGreen(newPixel)
newGreenSum += newGreen
newBlue = getBlue(newPixel)
newBlueSum += newBlue
totalPix = getWidth(newPic)*getHeight(newPic)
newTuple = (newPic, newRedSum/(totalPix), newGreenSum/(totalPix), newBlueSum/(totalPix))
picList.append(newTuple)
pic = makePicture("{}.jpg".format(fileName))
finalPic = makePicture(50*getWidth(pic),50*getHeight(pic))
show(pic)
for pixel in getPixels(pic):
picX = getX(pixel)
picY = getY(pixel)
picRed = getRed(pixel)
picGreen = getGreen(pixel)
picBlue = getBlue(pixel)
minDiff = 256
for pixelPic in picList:
redDiff = picRed - pixelPic[1]
greenDiff = picGreen - pixelPic[2]
blueDiff = picBlue - pixelPic[3]
magDiff = (redDiff**2+greenDiff**2+blueDiff**2)**(1/2)
if magDiff < minDiff:
minDiff = magDiff
savePic = pixelPic[0]
for saveX in range(getWidth(savePic)+1):
for saveY in range(getHeight(savePic)+1):
copyPixel = getPixel(savePic, saveX,saveY)
setRed(getPixel(finalPic, saveX+(picX*50), saveY+(picY*50)), getRed(copyPixel))
setGreen(getPixel(finalPic, saveX+(picX*50), saveY+(picY*50)), getGreen(copyPixel))
setBlue(getPixel(finalPic, saveX+(picX*50), saveY+(picY*50)), getBlue(copyPixel))
show(finalPic)
savePicture(finalPic,"{}.jpg".format(newFileName))
collageMaker("Piedmont2", 48, "PiedmontCollage")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment