Wang Tiles in Python

After reading about others’ development strategies for the 2013 7DRL I stumbled upon a post by one developer who mentioned off-handedly using Wang tiles for the level generation in his game. Naturally, my interest was piqued as I have always been interested in procedural generation and never had heard of this concept before. After searching I found a rather sterile Wikipedia entry followed by this rather useful article on the topic. The core idea of Wang tiles is that as long as all the edges of each tile in a tiled surface match the edges of their neighbors the tiles will appear congruous and can be used to add complexity to a texture or game easily.

Interestingly enough, it’s also easy to generate an entire grid and fill it with Wang tiles. You can place the tiles row by row and you only need to ensure each new tiles’ connected edges match the tiles already laid down above and to the left of it (if those tiles exist.) Otherwise, you can use any tile in the set. I decided to implement my own Wang tiles system using pygame. As you can see, the implementation is straightforward and allows for easy expansion for adding more side-types (currently having two: closed or open.) I’ve added a snippet of the resulting image generated by the program below. Wang tiles are a very interesting, and simple, concept. I’m glad I discovered them as I’m sure I’ll put them to good use in the future!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s