davide1409

mixer

Nov 12th, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def mixer(p1, p2) :
  2. # @param p1: Picture
  3. # @param p2: Picture;
  4.   canvas = makeEmptyPicture(getWidth(p1),getHeight(p1))
  5.   for b in range(0, 101, 5):
  6.     blendPictures(p1, p2, b, canvas)
  7.     repaint(canvas)
  8.  
  9. def blendPictures(pict1,pict2,blendFactor,canvas) :
  10. # @param pict1: Picture
  11. # @param pict2: Picture
  12. # @param blendFactor: int
  13. # @param canvas: Picture
  14.  
  15.   for x in range(0, getWidth(pict1)) :
  16.     for y in range(0,getHeight(pict1)):
  17.       pix1 = getPixel(pict1, x, y)
  18.       pix2 = getPixel(pict2, x, y)
  19.       pixCanvas = getPixel(canvas,x,y)
  20.       newRed = (blendFactor/100.0)*getRed(pix1)+(1-(blendFactor/100.0))*getRed(pix2)
  21.       newGreen = (blendFactor/100.0)*getGreen(pix1)+(1-(blendFactor/100.0))*getGreen(pix2)
  22.       newBlue = (blendFactor/100.0)*getBlue(pix1)+(1-(blendFactor/100.0))*getBlue(pix2)
  23.      
  24.       color = makeColor(newRed,newGreen,newBlue)
  25.       setColor(pixCanvas,color)
Add Comment
Please, Sign In to add comment