Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created April 18, 2017 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryancdotorg/67a2a8d351ccaf746881066009e5390c to your computer and use it in GitHub Desktop.
Save ryancdotorg/67a2a8d351ccaf746881066009e5390c to your computer and use it in GitHub Desktop.
#!/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