Wang tile generator
The algorithm generates an aperiodic tiling of the following 16 tiles:
The tiles use 6 colors, shown here as red, yellow, cyan, purple, green and grey.
The tiles aren't uniformly distributed in the resulting image. This is their frequency distribution:
![Tile Frequency](//github.com/josephg/wangjs/raw/master/tile freq.png)
And the colors aren't evenly distributed either. Here's their frequency distribution:
![Color Frequency](//github.com/josephg/wangjs/raw/master/color freq.png)
wang(width, height, [seed]) function returns a Uint8Array of width x height tile indexes. The returned array starts with the first row, then the next row, and so on. Each tile index is an integer from 0-15, corresponding to a tile in the diagram above.
// If you're using node...var wang = require'./wang'wang// Generate 2 rows of 5 wang tilesvar width = 5;var height = 3;var arr = wangwidth height; // width, height// Print out the tile indexesforvar y = 0; y < height; y++forvar x = 0; x < width; x++console.log"At "+x+","+y + ": " arrx + y * width;
Here's the output:
$ node test.jsAt 0,0: 11At 1,0: 3At 2,0: 1At 3,0: 9At 4,0: 3At 0,1: 0At 1,1: 14At 2,1: 13At 3,1: 0At 4,1: 12At 0,2: 9At 1,2: 5At 2,2: 2At 3,2: 8At 4,2: 1
Or, as a picture:
If you need it, here's a list of the colors on each tile. Each tile is described in left-top-right-bottom order.
c = r:0y:1b:2g:3p:4w:5# A list of the colors of each tile, left, top, right, bottom.colors =crcycycr# 0cgcbcbcg# 1cbcpcpcb# 2cwcgcgcw# 3cbcpcbcg# 4cwcgcbcg# 5cgcbcpcb# 6cgcbcgcw# 7cpcrcgcy# 8cbcrcwcy# 9cpcrcbcr# 10cgcycwcy# 11cycwcrcb# 12cycgcrcp# 13cycwcycg# 14crcbcrcp# 15