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:
And the colors aren't evenly distributed either. Here's their frequency distribution:
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 = wang// Generate 2 rows of 5 wang tilesvar width = 5;var height = 3;var arr = ; // width, height// Print out the tile indexesforvar y = 0; y < height; y++forvar x = 0; x < width; x++console;
Here's the output:
$ node test.js At 0,0: 11 At 1,0: 3 At 2,0: 1 At 3,0: 9 At 4,0: 3 At 0,1: 0 At 1,1: 14 At 2,1: 13 At 3,1: 0 At 4,1: 12 At 0,2: 9 At 1,2: 5 At 2,2: 2 At 3,2: 8 At 4,2: 1
Or, as a picture:
Tile color list
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