@name hexc8
@inputs EGP:wirelink
@outputs 
@persist EGPN
@trigger none

function array hexagon( Pos:vector2, Len ) {
    local Array = array()
    for (I = 0, 360, 60) {
        local Dir = vec2(0, 1):rotate(I)
        Array:unshiftVector2( Pos + Dir*Len )
    }    
    return Array
}

function wirelink:egpHexagon( Index, Pos:vector2, Len ) {
    local Array = array()
    for (I = 0, 360, 60) {
        local Dir = vec2(1, 0):rotate(I)
        Array:unshiftVector2( Pos + Dir*Len )
    }
    EGP:egpPoly(Index, Array)
}

EGP:egpClear()

#EGPN++
#EGP:egpPoly(EGPN, hexagon(vec2(256,256), 24))
#EGP:egpColor(EGPN, vec(255, 255, 255))


Ranks = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
Files = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L")

Index = 1
Cells = table()

for (I = 0, 5) {
    for (J = 0, 5 + I) {
        Cells[Index, table] = table(
            "rank" = Ranks[J + 1, number], # integer
            "file" = Ranks[I + 1, number], # integer
            "cell" = Files[I + 1, string] + Ranks[J + 1, number] # string
        )
        Index++    
    }
}

local SidePix = 24
local SidePix2 = SidePix*2

for (I = 1, 6) {
    local Cell = Cells[I, table]
    
    local X = Cell["file", number] # left/right (file)
    local Y = Cell["rank", number]  # up/down (rank)

    EGPN++
    
    local PX = X*SidePix2
    local PY = Y*(SidePix2/sqrt(3)) - X*SidePix
    
    EGP:egpHexagon(EGPN, vec2(64 + PX, 64 + PY), SidePix)
    
    #EGP:egpHexagon(EGPN, vec2(128 + X*(12 - sqrt(3)), 256 + Y*12 - 6*X), SidePix)

}
