Generate 47 tiles template

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Generate 47 tiles template

Post by darkfrei »

Hi all!

Here is a small tool to generate 47 tiles as:
sprites-47.png
sprites-47.png (4.1 KiB) Viewed 2275 times
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
Attachments
subtiles-01.love
License CC0
(1.69 KiB) Downloaded 93 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Generate 47 tiles template

Post by pgimeno »

Why the duplicates?
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: Generate 47 tiles template

Post by darkfrei »

pgimeno wrote: Sat Nov 26, 2022 8:25 am Why the duplicates?
The code looks nice, but I don't know why I have duplicates. Maybe I need to check if it was already done OR to optimize the condition logic.

Update: the first was easier:
CC0
CC0
sprites-47.png (430 Bytes) Viewed 1544 times
Grass
Stone
Dirt
Sand
Water
Wood
Brick
Cobblestone
Ice
Snow
Lava
Mud
Sandstone
Marble
Granite
Metal
Crystal
Mossy
Gravel
Mossy Stone
Cloud
Bush
Tree
Flower
Bushes
Rocks
Fence
Path
Bridge
Castle Wall
Castle Floor
Swamp
Cactus
Ruins
Cave Entrance
Cave Floor
Cave Wall
Dungeon Floor
Dungeon Wall
Crystal Cave
Crystal Wall
Crystal Floor
Ruined Floor
Ruined Wall
Volcanic Rock
Volcanic Lava
Void (Empty or Transparent)
Stone Tile (Base):

Solid stone tile as a base reference.
Stone-Grass Transition:

Stone transitioning smoothly into grass.
Stone-Dirt Transition:

Stone transitioning smoothly into dirt.
Stone-Sand Transition:

Stone transitioning smoothly into sand.
Stone-Water Transition:

Stone near the water edge.
Stone-Wood Transition:

Stone transitioning smoothly into a wooden floor.
Stone-Brick Transition:

Stone transitioning smoothly into brick.
Stone-Cobblestone Transition:

Stone transitioning into cobblestone.
Stone-Ice Transition:

Stone near icy terrain.
Stone-Snow Transition:

Stone transitioning into snowy terrain.
Stone-Lava Transition:

Stone near lava.
Stone-Mud Transition:

Stone transitioning into muddy terrain.
Stone-Sandstone Transition:

Stone transitioning into sandstone.
Stone-Marble Transition:

Stone transitioning into marble.
Stone-Granite Transition:

Stone transitioning into granite.
Stone-Metal Transition:

Stone transitioning into metallic terrain.
Stone-Crystal Transition:

Stone near crystal formations.
Mossy Stone Transition:

Stone with mossy overgrowth.
Stone-Gravel Transition:

Stone transitioning into gravel.
Mossy Stone Edge:

Stone with mossy edges.
Stone-Cloud Transition:

Stone floating in the clouds.
Stone-Bush Transition:

Stone with bushes.
Stone-Tree Transition:

Stone with tree roots.
Stone-Flower Transition:

Stone with flowers.
Stone-Bushes Transition:

Stone with dense bushes.
Stone-Rocks Transition:

Stone surrounded by rocks.
Stone-Fence Transition:

Stone with a fence nearby.
Stone-Path Transition:

Stone forming a pathway.
Stone-Bridge Transition:

Stone forming a bridge.
Stone-Castle Wall Transition:

Stone transitioning into castle walls.
Attachments
subtiles-02.love
CC0
(1.81 KiB) Downloaded 66 times
Last edited by darkfrei on Thu Feb 01, 2024 12:16 pm, edited 2 times in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
kuinashi101
Prole
Posts: 7
Joined: Tue Feb 21, 2023 9:47 am

Re: Generate 47 tiles template

Post by kuinashi101 »

This is helpful for making tool like procedural generate tileset, thanks for share :nyu:
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests