-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataviz3D.py
42 lines (30 loc) · 1 KB
/
dataviz3D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Image, ImageDraw, struct, sys, os
if len(sys.argv) != 3:
print "dataviz3D.py for.exe bar.png"
os._exit(1)
fileSize = os.path.getsize( sys.argv[1] )
imageLayers = 40
size = ( 256, 256 )
with open(sys.argv[1], "rb") as f:
x = struct.unpack('B', f.read(1))[0]
y = struct.unpack('B', f.read(1))[0]
for layer in range(imageLayers):
im = Image.new( 'RGB', size )
draw = ImageDraw.Draw( im )
for i in range((fileSize/imageLayers)):
try:
r, g, b = im.getpixel( (x, y) )
if r < 255:
draw.point((x, y), fill=( r+2, g, b))
elif g < 255:
draw.point((x, y), fill=( r, g+2, b))
else:
draw.point((x, y), fill=( r, g, b+2))
x = y
y = struct.unpack('B', f.read(1))[0]
except Exception, e:
break
del draw
im.save( str(layer) + sys.argv[2], "PNG")
del im
raw_input("Press Enter to continue...")