Skip to content

Instantly share code, notes, and snippets.

@zopieux
Created February 8, 2024 19:16
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 zopieux/708c3a9ff1d5bd68a271a96fe5942efa to your computer and use it in GitHub Desktop.
Save zopieux/708c3a9ff1d5bd68a271a96fe5942efa to your computer and use it in GitHub Desktop.
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages (p: [ p.numpy ])"
import json
import sys
import numpy as np
import collections
import binascii
data = json.load(open(sys.argv[1]))
frame = data['frames'][0]
matrix = np.full((21, 6), "#000000", dtype="S10")
for col, row_data in frame.items():
for row, color in row_data.items():
matrix[(int(col),int(row))] = color
matrix = matrix.transpose()
def to_bin(idx, row):
row = b''.join(binascii.unhexlify(r[1:]) for r in row)
return bytes([idx, 0, 20]) + row
full = b''.join(to_bin(i, matrix[i,:]) for i in range(matrix.shape[0]))
sys.stdout.buffer.write(full)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment