local node = Node:extend('nodes.at', {
})
-- local papa = love.graphics.newImage("papa.png")
local h = 25.0
local v = {
	{-h, -h, -h},
	{ h, -h, -h},
	{ h,  h, -h},
	{-h,  h, -h},
	{-h, -h,  h},
	{ h, -h,  h},
	{ h,  h,  h},
	{-h,  h,  h}
}

local c = {
	{0, 1, 31},
	{1, 2, 31},
	{2, 3, 31},
	{3, 0, 31},
	{0, 4, 34},
	{1, 5, 34},
	{2, 6, 34},
	{3, 7, 34},
	{4, 5, 32},
	{5, 6,32},
	{6, 7,32},
	{7, 4,32}
}

local E = 100 * math.tan(2*math.pi/3)

function to2d(p) return p[1] * E / (p[3]+E), p[2] * E / (p[3]+E) end

function node:render()
  love.graphics.setColor( 0, 0, 0 )
  love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
  love.graphics.setColor( 1.0, 1.0, 1.0 )
  local w = love.graphics.getWidth() / 2
  local h = love.graphics.getHeight() / 2
  local scl = 6
	for _, p in ipairs(c) do
		x1, y1 = to2d(v[p[1]+1])
		x2, y2 = to2d(v[p[2]+1])
    love.graphics.line(x1 * scl + w, y1 * scl + h, x2 * scl + w, y2 * scl + h)
	end
end

function node:update(dt)
  for _, vec in ipairs(v) do
    angle = -dt/3
    nv0 = math.cos(angle) * vec[1] + math.sin(angle) * vec[3]
    nv2 = -math.sin(angle) * vec[1] + math.cos(angle) * vec[3]
    vec[1] = nv0
    vec[3] = nv2
    angle = dt
    nv1 = math.cos(angle) * vec[2] - math.sin(angle) * vec[3]
    nv2 = math.sin(angle) * vec[2] + math.cos(angle) * vec[3]
    vec[2] = nv1
    vec[3] = nv2
  end
end

return node
