Created
April 18, 2017 19:54
-
-
Save ryancdotorg/67a2a8d351ccaf746881066009e5390c to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
from PIL import Image | |
INFILE = 'place.csv' # expects ts (seconds), x, y, hex color (without #) sorted by timestamp | |
OUTDIR = 'place_frames' # a directory, expected to exist | |
def hex2rgb(h): | |
return (int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)) | |
img = Image.new( 'RGB', (1001,1001), "white") | |
pixels = img.load() # create the pixel map | |
n = 0 | |
prev_ts = 0 | |
with open(INFILE) as f: | |
for line in iter(f.readline,''): | |
line = line.strip() | |
ts, x, y, color = line.split(',') | |
ts = int(ts) | |
x = int(x) | |
y = int(y) | |
if ts != prev_ts: | |
n += 1 | |
print 'saving %s/%u.png %7.3f%%' % (OUTDIR, prev_ts, n/(86400*.03)) | |
img.save('%s/%u.png' % (OUTDIR, prev_ts), 'PNG') | |
prev_ts = ts | |
pixels[x,y] = hex2rgb(color) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment