Advertisement
SimonMage

Trascolorazione Continua, esercizio da completare

Nov 2nd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Completare il codice seguente per miscelare progressivamente due immagini;
  2. # si assuma per semplicita' che la seconda immagine abbia sempre dimensioni uguali o
  3. # maggiori di quelle della prima immagine;
  4. # i ... indicano la mancanza di una o piu' parti di codice
  5. def mixer(p1, p2) :
  6. # @param p1: Picture
  7. # @param p2: Picture
  8.   canvas = makeEmptyPicture(getWidth(p1),getHeight(p1))
  9.   for b in range(0, 101, 5):
  10.     blendPictures(p1, p2, b, canvas)    
  11.     repaint(canvas)      
  12.  
  13. def blendPictures(pict1, pict2, blendFactor, canvas) :
  14. # @param pict1: Picture
  15. # @param pict2: Picture
  16. # @param blendFactor: int; Quante volte viene eseguita la trascolorazione
  17. # @param canvas: Picture; Immagine bianca
  18.   for x in range(0, getWidth(pict1)) :
  19.     for y in range(0, getHeight(pict1)) :
  20.       pix1 = getPixel(pict1, x, y)
  21.       pix2 = getPixel(pict2, x, y)      
  22.       pixCanvas = getPixel(canvas, x, y)
  23.       newRed = (blendFactor/100.0)*getRed(pix1)+(1-(blendFactor/100.0))*getRed(pix2)
  24.       newGreen = (blendFactor/100.0)*getGreen(pix1)+(1-(blendFactor/100.0))*getGreen(pix2)
  25.       newBlue = (blendFactor/100.0)*getBlue(pix1)+(1-(blendFactor/100.0))*getBlue(pix2)
  26.       color = makeColor(newRed,newGreen,newBlue)
  27.       setColor(pixCanvas, color)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement