function createHex(centerX, centerY) local hex = {} hex.centerX = centerX hex.centerY = centerY hex.size = 45 --The height is size *2 --The width is sqrt(3)/2 * height --Horizontal distance between two hexes is horiz = width hex.height = hex.size * 2 hex.width = math.sqrt(3)/2 * hex.height local lastX = nil local lastY = nil hex.sides = {} for i=0,6 do local angle = 2 * math.pi/6 * (i + 0.5) local x = hex.centerX + hex.size * math.cos(angle) local y = hex.centerY + hex.size * math.sin(angle) if i > 0 then hex.sides[i] = {lastX, lastY, x, y} end lastX = x lastY = y end return hex end function love.load() end function love.update() end function love.draw() love.graphics.setColor({255,255,255,255}) --create our first hex #note: this will all end up --in a single for loop to draw a complete grid temp=createHex (300,300) hex1=createHex(0+temp.width,0+temp.height) for i=1, #hex1.sides do love.graphics.line(unpack(hex1.sides[i])) end --Here we create another hex and place it to the side newCenterX = hex1.centerX + hex1.width hex2=createHex(newCenterX,hex1.centerY) for i=1, #hex2.sides do love.graphics.line(unpack(hex2.sides[i])) end -- Here we want to move down a row and base it from the first hex newCenterY = hex1.centerY+(hex1.height * 3/4) newCenterX = (hex1.centerX + hex2.centerX)/2 hex3 = createHex(newCenterX, newCenterY) for i=1, #hex3.sides do love.graphics.line(unpack(hex3.sides[i])) end end