Advertisement
MaxDvc

alternateColumns

Oct 22nd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. pict = makePicture(pickAFile())
  2. width = getWidth(pict)
  3. height = getHeight(pict)
  4. newPict = makeEmptyPicture(width,height)
  5.  
  6. def alternateColumns(w,pict,newPict):
  7. #@param:
  8. #  w: int, column width, must be a divisor of width;
  9. #  pict: picture;
  10. #  newPict: an empty picture that has the same size of "pict";
  11.   for i in range(0,width,width/(width/(2*w))):
  12.     moveColumnFromAToB(i,w)
  13.     moveColumnFromBToA(i,w)
  14.   show(newPict)
  15.  
  16. def moveColumnFromAToB(i,w):
  17. #@param:
  18. #  i: int; first pixel on the x axis
  19. #  w: int, column width, must be a multiple of width;
  20.   for y in range(0,height):
  21.       for x in range(i,i+w):
  22.         pix = getPixel(pict,min(width-1,x),y)
  23.         nPix = getPixel(newPict,min(width-1,x+w),y)
  24.         nc = getColor(nPix)
  25.         c = getColor(pix)
  26.         setColor(nPix,c)
  27.  
  28. def moveColumnFromBToA(i,w):
  29. #@param:
  30. #  i: int; first pixel on the x axis
  31. #  w: int, column width, must be a multiple of width;
  32.     for y in range(0,height):
  33.       for x in range(i+w,i+2*w):
  34.         pix = getPixel(pict,min(width-1,x),y)
  35.         nPix = getPixel(newPict,min(width-w,x-w),y)
  36.         nc = getColor(nPix)
  37.         c = getColor(pix)
  38.         setColor(nPix,c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement