Compare commits

...

1 commit

Author SHA1 Message Date
71f98fd831 Centered grid 2025-10-24 12:52:33 +03:00
3 changed files with 8 additions and 5 deletions

View file

@ -7,6 +7,7 @@ VERSION = 'v0.2'
---@field pointRadius number Radius of each grid point, relative to cellSize
---@field linePointRadius number Radius of line start/end points, relative to cellSize
---@field cellSize number Size of each grid cell
---@field gridOffset number X offset of grid processing
---@field lineStyle string love2d line style setting
---@field lineWidth number love2d line width setting
---@field menuLineWidth number love2d line width for buttons
@ -17,6 +18,7 @@ Config = {
linePointRadius = 0.4,
cellSize = 30,
gridOffset = 160,
lineStyle = "smooth",
lineWidth = 0.1,

View file

@ -39,8 +39,9 @@ function Grid:draw()
end
for y = 1, self.size.y do
local px, py = x * Config.cellSize, y * Config.cellSize
love.graphics.circle( "fill", px - Config.cellSize / 2, py - Config.cellSize / 2, Config.cellSize * Config.pointRadius)
local gp = GridPoint:new(x, y)
local px, py = gp:globalCoords()
love.graphics.circle( "fill", px, py, Config.cellSize * Config.pointRadius)
end
end
-- Draw lines

View file

@ -9,7 +9,7 @@ GridPoint = Point
---@return Point
function GridPoint:absolute()
return Point:new(
self.x * Config.cellSize,
self.x * Config.cellSize + Config.gridOffset,
self.y * Config.cellSize
)
end
@ -17,7 +17,7 @@ end
-- Same as coords, but converted to global coords
---@return number, number
function GridPoint:globalCoords()
return self.x * Config.cellSize - Config.cellSize / 2,
return self.x * Config.cellSize - Config.cellSize / 2 + Config.gridOffset,
self.y * Config.cellSize - Config.cellSize / 2
end
@ -25,7 +25,7 @@ end
---@param point Point
---@return GridPoint
function GridPoint.snapCoords( point )
local x = math.ceil( point.x / Config.cellSize )
local x = math.ceil( (point.x - Config.gridOffset) / Config.cellSize )
local y = math.ceil( point.y / Config.cellSize )
return GridPoint:new( x, y )
end