Created
April 5, 2013 10:55
-
-
Save nadvornix/5318416 to your computer and use it in GitHub Desktop.
python2.6 display.py output.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Image,sys,ImageDraw | |
| if len(sys.argv)<2: | |
| print "missing filename" | |
| sys.exit() | |
| filename=sys.argv[1] | |
| f=file(filename) | |
| def evalM(s): | |
| parts=s.split("/") | |
| if len(parts)==1: | |
| return float(parts[0]) | |
| if len(parts)==2: | |
| return float(parts[0])/float(parts[1]) | |
| raise ValueError | |
| lines=[] | |
| for line in f.readlines(): | |
| color,x1,y1,x2,y2=line.split() | |
| x1,y1,x2,y2=evalM(x1),evalM(y1),evalM(x2),evalM(y2) | |
| lines.append((color,x1,y1,x2,y2)) | |
| maxy=max(map(lambda a: max(a[2],a[4]),lines)) | |
| miny=min(map(lambda a: min(a[2],a[4]),lines)) | |
| maxx=max(map(lambda a: max(a[1],a[3]),lines)) | |
| minx=min(map(lambda a: min(a[1],a[3]),lines)) | |
| lenx=maxx-minx | |
| leny=maxy-miny | |
| # print int(lenx), int(leny) | |
| # sys.exit() | |
| img=Image.new('RGB', (int(lenx+20), int(leny+20)), (255,255,255)) | |
| draw = ImageDraw.Draw(img) | |
| def getColor(color): | |
| if color=="i": | |
| return "#0000FF" | |
| if color=="o": | |
| return "#00FF00" | |
| if color=="c": | |
| return "#FF0000" | |
| return color | |
| for color,x1,y1,x2,y2 in lines: | |
| color = getColor(color) | |
| draw.line((int(x1-minx), int(y1-miny), int(x2-minx), int(y2-miny)), fill=color) | |
| img.save("test.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment