Generate 47 tiles template
Posted: Fri Nov 25, 2022 11:51 am
Hi all!
Here is a small tool to generate 47 tiles as:
The size of tile (pixels per tile) and image dpi (subpixels per unit "pixel") can be changed.
Here is a small tool to generate 47 tiles as:
The size of tile (pixels per tile) and image dpi (subpixels per unit "pixel") can be changed.
Code: Select all
-- main function:
local function getCanvas()
local subtileSize = 4 -- pixels in tile
local dpiscale = 8 -- subpixels per pixel
local canvasWidth = 7*(subtileSize+1)+1
local canvasHeight = 16*(subtileSize+1)+1
local canvas = love.graphics.newCanvas (canvasWidth, canvasHeight, {dpiscale = dpiscale})
canvas:setFilter("linear", "nearest")
love.graphics.setLineStyle("rough")
love.graphics.setLineWidth(1)
love.graphics.setCanvas(canvas)
love.graphics.setPointSize (1)
local n = 0
for i = 0, 255 do
local a = not(i%2 == 0)
local b = not(math.floor(i/2)%2 == 0)
local c = not(math.floor(i/4)%2 == 0)
local d = not(math.floor(i/8)%2 == 0)
local ab = not((math.floor(i/16)%2 == 0)) and a and b
local bc = not((math.floor(i/32)%2 == 0)) and b and c
local cd = not((math.floor(i/64)%2 == 0)) and c and d
local da = not((math.floor(i/128)%2 == 0)) and d and a
local x = 1.5 + math.floor ((n)/16)*(subtileSize+1)
local y = (n-16)%16*(subtileSize+1)+1.5
-- outline
love.graphics.setColor (1,0,1)
love.graphics.rectangle ('line', x-1, y-1, subtileSize+1,subtileSize+1)
-- -- background
love.graphics.setColor (0.55,0.55,0.55)
love.graphics.rectangle ('fill', x-0.5, y-0.5, subtileSize,subtileSize)
-- sides and corners:
love.graphics.setColor (0.75, 0.75, 0.75)
local variations = {
{ab, bc, cd, da},
{ab, bc, cd},
{ab, bc, da},
{ab, cd, da},
{bc, cd, da},
{ab, bc},
{ab, da},
{cd, da},
{bc, cd},
{ab, cd},{bc, da},
{ab},{bc},{cd},{da},
{false},
}
for j, variant in ipairs (variations) do
local alltrue = true
for k, bool in ipairs (variant) do
if not bool then
alltrue = false
break
end
end
if alltrue then
drawLines (ab,bc,cd,da, x,y, subtileSize)
drawPoints (a,b,c,d, x,y, subtileSize)
n = n+1
break
elseif i < 16 then
drawPoints (a,b,c,d, x,y, subtileSize)
n = n+1
break
end
end
end
love.graphics.setCanvas()
return canvas
end