Advertisement
LexManos

Untitled

Apr 13th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. import os, sys, pprint
  2.  
  3. def main():
  4.     patches = [['A1', 'A2', 'A3', 'A4'],
  5.                ['B1', 'B2', 'B3', 'B4'],
  6.                ['C1', 'C2', 'C3', 'C4'],
  7.                ['D1', 'D2', 'D3', 'D4']]
  8.    
  9.     for y in range(0, len(patches)):
  10.         for x in range(0, len(patches[0])):
  11.             regions = makePatch([7,2], [x,y], 1024, 8, 4)
  12.             print '%s: {' % patches[y][x]
  13.             print '    regions: ['
  14.             for z in range(0, 9):
  15.                 print '        { height: %d, width: %d, x: %d, y: %d }%s' % (regions[z]['height'], regions[z]['width'], regions[z]['x'], regions[z]['y'], '' if z == 8 else ',')
  16.             print '    ],'
  17.             print '    color: red'
  18.             print '}%s' % ('' if x == len(patches[0]) - 1 and y == len(patches) - 1  else ',')
  19.    
  20. def makePatch(big, small, size, cBig, cSmall):
  21.     smallSize = size / cBig / cSmall
  22.     startX = big[0] * cSmall * smallSize + (small[0] * smallSize)
  23.     startY = big[1] * cSmall * smallSize + (small[1] * smallSize)
  24.     regionSize = smallSize / 3
  25.     regions = []
  26.    
  27.     sizes = [[8, 8], [16, 8], [8, 8],
  28.              [8,16], [16,16], [8,16],
  29.              [8, 8], [16, 8], [8, 8]]
  30.              
  31.     offY = 0
  32.     for y in range(0, 3):
  33.         offX = 0
  34.         for x in range(0, 3):
  35.             size = sizes[y * 3 + x]
  36.             regions.append({'height' : size[1] if size[1] != 16 else 1, 'width' : size[0] if size[0] != 16 else 1, 'x' : startX + offX, 'y' : startY + offY})
  37.             offX += size[0]
  38.         offY += sizes[y * 3][1]
  39.     return regions
  40.    
  41. if __name__ == '__main__':
  42.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement