Skip to content

Instantly share code, notes, and snippets.

@jnwhiteh
Created February 28, 2016 13:35
Show Gist options
  • Save jnwhiteh/66c4220559c1b155fe46 to your computer and use it in GitHub Desktop.
Save jnwhiteh/66c4220559c1b155fe46 to your computer and use it in GitHub Desktop.
a = [
0b10000000,
0b01000000,
0b00100000,
0b00010000,
0b00011000,
0b00000100,
0b00010010,
0b00010001,
]
def printglyph(glyph):
"""Print a glyph defined with rows"""
for row in glyph:
s = ""
for mask in [1 << (7 - bit) for bit in range(0, 8)]:
bit = row & mask
s += "X" if bit > 0 else " "
print s
def rotate(glyph):
"""Rotate a column-defined glyph to column-defined"""
result = []
for mask in [1 << (7 - bit) for bit in range(0, 8)]:
column = 0
for rowIndex in range(0, 8):
row = glyph[rowIndex]
if (row & mask) > 0:
column |= (1 << (7 - rowIndex))
result.append(column)
return result
assert a == rotate(rotate(a))
printglyph(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment