Page 1 of 1

Generate 47 tiles template

Posted: Fri Nov 25, 2022 11:51 am
by darkfrei
Hi all!

Here is a small tool to generate 47 tiles as:
sprites-47.png
sprites-47.png (4.1 KiB) Viewed 3528 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

Re: Generate 47 tiles template

Posted: Sat Nov 26, 2022 8:25 am
by pgimeno
Why the duplicates?

Re: Generate 47 tiles template

Posted: Fri Jan 27, 2023 1:00 pm
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 2797 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.

Re: Generate 47 tiles template

Posted: Tue Feb 21, 2023 10:04 am
by kuinashi101
This is helpful for making tool like procedural generate tileset, thanks for share :nyu: