from PIL import ImageDraw, Image
from math import cos,sin,radians
from random import randint
import sys

a = "a0A1b2B3c4C5d6D7e8E9f!F,g.G/h?H<i>I:j;J'k\"K\\l|L/m M\nn\tN@o#O$p%P^q&Q*r(R)s_S-t+T=u{U}v[V]w W x X y Y z Z"
if len(a) > 128:
    print("TOO MANY CHARACTERS")
    sys.exit(1)

# for i in a:
#     print("%s -> %d %d %d %d %d %d %d "%(i,
#         1 if a.index(i) & 1 == 1 else 0,
#         1 if a.index(i) & 2 == 2 else 0,
#         1 if a.index(i) & 4 == 4 else 0,
#         1 if a.index(i) & 8 == 8 else 0,
#         1 if a.index(i) & 16 == 16 else 0,
#         1 if a.index(i) & 32 == 32 else 0,
#         1 if a.index(i) & 64 == 64 else 0,
#         ))

# sys.exit(0)
WHITE=(255,255,255)
PINK=(217,154,197)
BLUE=(103,170,249)
BLACK=(0,0,0)

img = Image.new('RGB', (2560,1600), BLACK)
id = ImageDraw.Draw(img)


def hex(offset, size):
    points = []
    x,y = offset
    for angle in range(0, 360, 60):
        x += cos(radians(angle)) * size
        y += sin(radians(angle)) * size
        points.append((x, y))
    return points

def drawHex(id, sx,sy,s,c):
    ox = sx - cos(radians(120)) * s
    oy = sy - sin(radians(120)) * s

    id.polygon(hex((ox-s,oy-s*2),s), fill=BLUE if c & 1 == 1 else PINK)
    id.polygon(hex((ox+s,oy-s*2),s), fill=BLUE if c & 2 == 2 else PINK)

    id.polygon(hex((ox-s*2,oy),s), fill=BLUE if c & 4 == 4 else PINK)
    id.polygon(hex((ox,oy),s), fill=BLUE if c & 8 == 8 else PINK)
    id.polygon(hex((ox+s*2,oy),s), fill=BLUE if c & 16 == 16 else PINK)

    id.polygon(hex((ox-s,oy+s*2),s), fill=BLUE if c & 32 == 32 else PINK)
    id.polygon(hex((ox+s,oy+s*2),s), fill=BLUE if c & 64 == 64 else PINK)

q = """This is a test
0123456789%"""
s = 10
cutOff = int(2560/(s*7))
print (cutOff)
x,y = 0,0
for c in q:
    drawHex(id, s*2 + x*s*7, s*3 + y*s*7, s, a.index(c))
    x+=1
    if x >= cutOff or c == "\n":
        x,y = 0,y+1
img.show()
[((28, 6, 28, 42), 'PIL.Image.new', 'Image.new', ({(28, 16, 28, 21): '"""RGB"""', (28, 23, 28, 34): '(2560, 1600)', (28, 36, 28, 41): 'BLACK'}, {}), "('RGB', (2560, 1600), BLACK)", False, 'from PIL import ImageDraw, Image\n'), ((29, 5, 29, 24), 'PIL.ImageDraw.Draw', 'ImageDraw.Draw', ({(29, 20, 29, 23): 'img'}, {}), '(img)', False, 'from PIL import ImageDraw, Image\n'), ((9, 4, 9, 15), 'sys.exit', 'sys.exit', ({(9, 13, 9, 14): '(1)'}, {}), '(1)', False, 'import sys\n'), ((36, 17, 36, 31), 'math.radians', 'radians', ({(36, 25, 36, 30): 'angle'}, {}), '(angle)', False, 'from math import cos, sin, radians\n'), ((37, 17, 37, 31), 'math.radians', 'radians', ({(37, 25, 37, 30): 'angle'}, {}), '(angle)', False, 'from math import cos, sin, radians\n'), ((42, 18, 42, 30), 'math.radians', 'radians', ({(42, 26, 42, 29): '(120)'}, {}), '(120)', False, 'from math import cos, sin, radians\n'), ((43, 18, 43, 30), 'math.radians', 'radians', ({(43, 26, 43, 29): '(120)'}, {}), '(120)', False, 'from math import cos, sin, radians\n')]