Advertisement
davide1409

Ribaltamento Verticale e Ribaltamento Orizzontale 2.0

Oct 22nd, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. def ribaltamentoOrizzontale(pict):
  2. #@param pict: Picture
  3.   w,h = getWidth(pict), getHeight(pict)
  4.  
  5.   #creo un'immagine vuota per poi renderla identica a pict
  6.   newPict = makeEmptyPicture(w,h)
  7.   for y in range(h):
  8.     for x in range(w):
  9.       color = getColor(getPixel(pict,x,y))
  10.       setColor(getPixel(newPict,x,y),color)
  11.  
  12.   mirrorPoint = w/2
  13.   for j in range(h):
  14.     for i in range(mirrorPoint):
  15.       leftP = getPixel(newPict,i,j) # pixel attuale
  16.       rightP = getPixel(newPict,(w-i-1),j) # pixel specchiato
  17.       #swap tra pixel: attraverso lo scambio dei colori
  18.       colorL,colorR = getColor(leftP),getColor(rightP)
  19.       setColor(rightP, colorL)
  20.       setColor(leftP, colorR)
  21.      
  22.   show(newPict)
  23.  
  24. def ribaltamentoVerticale(pict):
  25. #@param pict: Picture
  26.   w,h = getWidth(pict), getHeight(pict)
  27.  
  28.   #creo un'immagine vuota per poi renderla identica a pict
  29.   newPict = makeEmptyPicture(w,h)
  30.   for y in range(h):
  31.     for x in range(w):
  32.       color = getColor(getPixel(pict,x,y))
  33.       setColor(getPixel(newPict,x,y),color)
  34.      
  35.   mirrorPoint = h/2
  36.   for i in range(w):
  37.     for j in range(mirrorPoint):
  38.       leftP = getPixel(newPict,i,j) # pixel attuale
  39.       rightP = getPixel(newPict,i,(h-j-1)) # pixel specchiato
  40.       #swap tra pixel: attraverso lo scambio dei colori
  41.       colorL,colorR = getColor(leftP),getColor(rightP)
  42.       setColor(rightP, colorL)
  43.       setColor(leftP, colorR)
  44.      
  45.   show(newPict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement