# cPy/Esp32 - printing and rotating a 8x8 bitmap for Max7219
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-07-18  initial release

# ====================== print and rotate pattern =========================

# print 8x8 bit pattern, 8 bytes, to console 
def print8x8(pattern):
    for mask in (0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01):
        for row in reversed(pattern):
            print('X', end=' ') if row & mask else print('.', end=' ')
        print()
    

# return 90 degree rotated 8x8 bit pattern
def rotate8x8(pattern):
    res = bytearray(8)
    for i in range(8):
        for j in range(8):
            res[i] |= ((pattern[j] >> i) & 1) << (7 - j)
    return res

# ========================= tests ===============================

def test():
    A = b'\x3c\x24\x24\x7e\x62\x62\x62\x00'
    print8x8(A)
    print()
    B = rotate8x8(A)			# rotate A by 90 degrees
    print8x8(B)
    

test()

# =========================== end ===============================

    
