variksoo21

Very messy code that generates CS 1.6 background tiles

Dec 18th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import time
  2. from Tkinter import Tk
  3. import math
  4. import os
  5. from tkFileDialog import askopenfilename
  6. from PIL import Image
  7.  
  8. Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
  9. filepath = askopenfilename() # show an "Open" dialog box and return the path to the selected file
  10. im = Image.open(filepath)
  11. print im.size
  12.  
  13. Width = im.size[0]
  14. Height = im.size[1]
  15.  
  16. Columns = int(math.ceil(im.size[0]/256)) + 1
  17. Rows = int(math.ceil(im.size[1]/256)) + 1
  18. print str(Columns) + " columns and " + str(Rows) + " rows."
  19.  
  20. filefolder = filepath.split("/")
  21. filefolder.pop(len(filefolder) - 1)
  22. filefolder = "/".join(filefolder)
  23. filename = filepath.split("/")[len(filepath.split("/")) - 1]
  24.  
  25. print(filepath)
  26. print filefolder
  27. print filename
  28.  
  29. Before = time.time()
  30. os.system("convert -crop 256x256 \"" + filepath + '" "' + filefolder + '/tile_%d.tga"')
  31. print time.time() - Before
  32.  
  33. RNS = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
  34. CNS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"]
  35.  
  36. N = 0
  37. R = 0
  38. while R < Rows:
  39.     C = 0
  40.     while C < Columns:
  41.         os.rename(filefolder + "/tile_" + str(N) + ".tga", filefolder + "/" + str(Width) + "_" + str(RNS[R]) + "_" + CNS[C] + "_loading.tga")        
  42.         N = N + 1
  43.         C = C + 1
  44.     R = R + 1
Advertisement
Add Comment
Please, Sign In to add comment