hexgrid: created a hex
This commit is contained in:
parent
dc86672f5a
commit
e1dc884af6
45
love/hexgrid/main.lua
Normal file
45
love/hexgrid/main.lua
Normal file
@ -0,0 +1,45 @@
|
||||
function createHex()
|
||||
local hex = {}
|
||||
hex.centerX = 300
|
||||
hex.centerY = 300
|
||||
hex.size = 45
|
||||
|
||||
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})
|
||||
hex1=createHex()
|
||||
|
||||
for i=1, #hex1.sides do
|
||||
love.graphics.line(unpack(hex1.sides[i]))
|
||||
end
|
||||
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user