#!/usr/bin/env nix-shell
#!nix-shell -p python3 -i python --pure

from math import *


# pointy top
def hex_to_pixel(hex_x, hex_y, size=1.2):
  x = size * (sqrt(3) * hex_x  +  sqrt(3)/2 * hex_y)
  y = size * (                          3/2 * hex_y)

  return (x, y)

# flat top
def hex_to_pixel2(hex_x, hex_y, size=1.2):
  x = size * (      3/2 * hex_x                    )
  y = size * (sqrt(3)/2 * hex_x  +  sqrt(3) * hex_y)

  return (x, y)


def iter_print(hexList, f=hex_to_pixel):
  for hex in hexList:
    pixel = f(*hex)

    hex_str = '({: d}, {: d})'.format(hex[0], hex[1])
    pixel_str = '({: .2f}, {: .2f})'.format(pixel[0], pixel[1])

    print('{0} -> {1}'.format(hex_str, pixel_str))


if __name__ == '__main__':
  hexList = [
    ( 0,  0),
    ( 0,  1),
    ( 1,  0),
    ( 0, -1),
    (-1,  0),
    ( 1,  1),
    (-1, -1),

    ( 0, -2),
    ( 1, -2),
    (-1, -2),
  ]

  iter_print(hexList, hex_to_pixel2)