Program to generate a larger image made up of different image tiles of the same size. You can specify how the image tiles connect to each other using a configuration file. Written in Python 3.
Create a directory with multiple same-sized tile raster images:
tiles
├─left-to-right.png
├─top-to-bottom.png
└─left-top-right-and-bottom.png
Create a proper configuration file (config.json
) in
JSON format:
{
"tiles": [
{
"filePath": "left-to-right.png",
"weight": 5,
"connectors": ["c", "", "c", ""]
},
{
"filePath": "top-to-bottom.png",
"weight": 5,
"connectors": ["", "c", "", "c"]
},
{
"filePath": "left-top-right-and-bottom.png",
"weight": 1,
"connectors": ["c", "c", "c", "c"]
}
]
}
Each object in the list of tiles
must have the following
name-value pairs:
<table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>filePath</td> <td>String</td> <td>The (relative) path to the image file of the tile, e. g. <code>left-to-right.png</code></td> </tr> <tr> <td>weight</td> <td>Number</td> <td> This number controls the probability of the tile appearing in the generated image, the higher the more often. </td> </tr> <tr> <td>connectors</td> <td>Array of Strings</td> <td> Each tile has four connectors, specified in the order <em>left</em>, <em>top</em>, <em>right</em>, <em>bottom</em>. </td> </tr> </tbody> </table>
To be placed in the grid, the connectors of the tile must match the adjacent tiles’ connectors.
Example:
{
"tiles": [
{
"filePath": "left-to-top.png",
"weight": 1,
"connectors": ["horizontal", "v", "none", "none"]
},
{
"filePath": "right-to-bottom.png",
"weight": 1.4,
"connectors": ["none", "none", "horizontal", "v"]
}
]
}
The tile left-to-top.png ╯
may be placed beneath the
tile right-to-bottom.png ╭
because its top connector
v
matches the bottom connector v
of
right-to-bottom.png. Following this logic, the tile left-to-top.png may
not be placed beneath another left-to-top.png tile because its top
connector v
does not match its bottom connector
none
.
Call tiler.py
passing the directory of tiles, the
configuration file, and the desired number of tile rows (4) and columns
(5) as arguments:
tiler.py -d tiles -c config.json 4 5
The resulting image is saved to output/tiled
.
https://rocketgit.com/user/syoung/Tile-Collections contains a set of tiles and a corresponding config.json.
$ git clone https://rocketgit.com/user/syoung/Tile-Collections
$ cd Tile-Collections/
$ tiler.py -c streets/config.json -d streets/png/ 5 6
INFO:No tile type provided; trying to guess tile type
INFO:Guessed tile type “r”