Advertisement
Guest User

fence.py

a guest
Jan 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import sys
  3. import csv
  4. from PIL import Image
  5.    
  6. if (len(sys.argv) != 2):
  7.   print('please a single give me a csv filename');
  8.   sys.exit(-1)
  9.  
  10. name = sys.argv[1]
  11.  
  12. coords = []
  13.  
  14. class Coord:
  15.   def __init__(self,x,y):
  16.     self.x = x
  17.     self.y = y
  18.  
  19. with open(sys.argv[1]) as csv_file:
  20.   csv_reader = csv.reader(csv_file)
  21.   next(csv_reader, None)
  22.   for row in csv_reader:
  23.     coords.append(Coord(int(row[1]),int(row[3])))
  24.  
  25. minX = 1000000
  26. maxX = -1000000
  27. minY = 1000000
  28. maxY = -1000000
  29.  
  30. for c in coords:
  31.   if (c.x < minX):
  32.     minX = c.x
  33.   if (c.x > maxX):
  34.     maxX = c.x
  35.   if (c.y < minY):
  36.     minY = c.y
  37.   if (c.y > maxY):
  38.     maxY = c.y
  39.  
  40. deltaX = maxX - minX
  41. deltaY = maxY - minY
  42.  
  43. for c in coords:
  44.   c.x = (c.x - minX)
  45.   c.y = (c.y - minY)
  46.  
  47. map = Image.new('1',(deltaX+1,deltaY+1),1)
  48. px = map.load()
  49.  
  50. for i,k1 in enumerate(coords):
  51.   k = coords[i-1]
  52.   for y in range(k.y,k1.y,1 if k1.y > k.y else -1):
  53.     px[k.x,y] = 0
  54.   for x in range(k.x,k1.x,1 if k1.x > k.x else -1):
  55.     px[x,k.y] = 0
  56.   px[k.x,k.y] = 0
  57.  
  58. map.save('map.png','png')
  59. print(minX,minY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement