Skip to content

Instantly share code, notes, and snippets.

@freshollie
Created April 3, 2017 23:11
Show Gist options
  • Save freshollie/e059d6232c77d300f75908c299593bde to your computer and use it in GitHub Desktop.
Save freshollie/e059d6232c77d300f75908c299593bde to your computer and use it in GitHub Desktop.
import PIL.Image
import numpy as np
import struct
import scipy.misc
class Place_Image:
COLOURS = [
"FFFFFF",
"E4E4E4",
"888888",
"222222",
"FFA7D1",
"E50000",
"E59500",
"A06A42",
"E5D900",
"94E044",
"02BE01",
"00D3DD",
"0083C7",
"0000EA",
"CF6EE4",
"820080"
]
@staticmethod
def convert_color(color_string):
return tuple(int(color_string[i:i+2], 16) for i in (0, 2 ,4))
def __init__(self):
# 1000x1000 display of white
self.pixels = [[Place_Image.convert_color(Place_Image.COLOURS[0]) for j in range(1000)] for i in range(1000)]
def set_pixel(self, x, y, colour):
self.pixels[y][x] = Place_Image.convert_color(Place_Image.COLOURS[colour])
def save(self):
scipy.misc.imsave("image.png", self.pixels)
def get_pixels(self):
pass
all_changes = []
with open("diffs.bin", "rb") as f:
image = Place_Image()
int_bytes = []
change = []
timestamp = 0
for c in f.read():
int_bytes.append(c)
if len(int_bytes) == 4:
change.append(int.from_bytes(bytes(int_bytes), byteorder="big", signed=False))
if (len(change) == 4):
all_changes.append(change)
if timestamp == 0:
timestamp = change[0]
# New snapshot
if change[0] > timestamp:
image.save()
break
image.set_pixel(change[1], change[2], change[3])
change = []
int_bytes = []
print(len(all_changes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment