Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Funzione che partendo da due immagini: flower1.jpg , flower2.jpg
- # contenute nella cartella mediasources: http://www.cc.gatech.edu/~mark.guzdial/mediacomp/mediasources-py2ed.zip
- # realizza un collage di 5 immagini con:
- # 1a flower1 originale
- # 2a flower2 originale
- # 3a flower1 in negativo
- # 4a flower2 senza il colore blu
- # 5a flower1 in negativo senza il colore rosso
- def collage(pict1, pict2):
- # @param pict1: Picture. flower1.jpg
- # @param pict1: Picture. flower2.jpg
- canvas = createCanvas(pict1)
- negPict1 = negative(pict1)
- noBluePict2 = removeBlue(pict2)
- noRedPict1 = removeRed(negPict1)
- allPicture = (pict1, pict2, negPict1, noBluePict2, noRedPict1)
- finalCollage = applyCollage(canvas, allPicture)
- show(finalCollage)
- def createCanvas(pict):
- # @param pict: Picture
- canvas = makeEmptyPicture(5*getWidth(pict), getHeight(pict))
- return canvas
- def negative(pict):
- # @param pict: Picture
- negPict1 = makeEmptyPicture( getWidth(pict), getHeight(pict))
- for x in range(getWidth(pict)):
- for y in range(getHeight(pict)):
- pxOriginal = getPixel(pict, x, y)
- pxNegative = getPixel(negPict1, x, y)
- setColor(pxNegative, makeColor(255 - getRed(pxOriginal), 255 - getGreen(pxOriginal), 255 - getBlue(pxOriginal)))
- return negPict1
- def removeBlue(pict):
- # @param pict: Picture
- noBluePict2 = makeEmptyPicture( getWidth(pict), getHeight(pict))
- for x in range(getWidth(pict)):
- for y in range(getHeight(pict)):
- pxOriginal = getPixel(pict, x, y)
- pxNoBlue = getPixel(noBluePict2, x, y)
- setColor(pxNoBlue, makeColor(getRed(pxOriginal), getGreen(pxOriginal), 0*getBlue(pxOriginal)))
- return noBluePict2
- def removeRed(pict):
- # @param pict: Picture
- noRedPict1 = makeEmptyPicture( getWidth(pict), getHeight(pict))
- for x in range(getWidth(pict)):
- for y in range(getHeight(pict)):
- pxOriginal = getPixel(pict, x, y)
- pxNoRed = getPixel(noRedPict1, x, y)
- setColor(pxNoRed, makeColor(0*getRed(pxOriginal), getGreen(pxOriginal), getBlue(pxOriginal)))
- return noRedPict1
- def applyCollage(canvas, allPicture):
- # @param canvas: Picture
- # @param allPicture: String
- startX = 0
- for pic in allPicture:
- for sourceX in range(getWidth(pic)):
- targetX = sourceX + startX
- for sourceY in range(getHeight(pic)):
- targetY = sourceY
- color = getColor(getPixel(pic, sourceX, sourceY))
- setColor(getPixel(canvas ,targetX, targetY), color)
- startX = targetX
- return canvas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement