Wang Tiling
A Simple Wang Tiling Generator
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CWangTiler Class Reference

Wang tiler. More...

#include <WangTiler.h>

Public Member Functions

 CWangTiler (size_t w, size_t h)
 Constructor. More...
 
 ~CWangTiler ()
 Destructor. More...
 
void Generate ()
 Generate tiling. More...
 
const size_t GetWidth () const
 Get width in tiles. More...
 
const size_t GetHeight () const
 Get height in tiles. More...
 
const size_t operator() (size_t i, size_t j) const
 Get tile index. More...
 

Private Member Functions

UINT Match (UINT x, UINT y)
 Choose random tile. More...
 

Private Attributes

UINT ** m_nTile = nullptr
 Array of tile indices. More...
 
size_t m_nWidth = 0
 Array width in tiles. More...
 
size_t m_nHeight = 0
 Array height in tiles. More...
 
std::default_random_engine m_stdRandom
 Pseudo-random number generator. More...
 

Detailed Description

The Wang tiler generates a pseudo-random rectangular array of tile indices into a set of 8 Wang tiles that seamlessly tile the plane.

Definition at line 37 of file WangTiler.h.

Constructor & Destructor Documentation

◆ CWangTiler()

CWangTiler::CWangTiler ( size_t  w,
size_t  h 
)

Set the pseudo-random number generator seed to timeGetTime(), the number of milliseconds since Windows last rebooted. This should be sufficiently unpredictable to make a good seed. Allocate memory for the tile array m_nTile.

Parameters
wWidth in tiles.
hHeight in tiles.

Definition at line 37 of file WangTiler.cpp.

◆ ~CWangTiler()

CWangTiler::~CWangTiler ( )

Deallocate memory from the tile array m_nTile.

Definition at line 52 of file WangTiler.cpp.

Member Function Documentation

◆ Generate()

void CWangTiler::Generate ( )

Generate a Wang tiling of width m_nWidth and height m_nHeight into m_nTile using m_stdRandom as a source of randomness.

Definition at line 72 of file WangTiler.cpp.

◆ GetHeight()

const size_t CWangTiler::GetHeight ( ) const

Reader function for m_nHeight.

Returns
m_nHeight

Definition at line 107 of file WangTiler.cpp.

◆ GetWidth()

const size_t CWangTiler::GetWidth ( ) const

Reader function for m_nWidth.

Returns
m_nWidth

Definition at line 100 of file WangTiler.cpp.

◆ Match()

UINT CWangTiler::Match ( UINT  x,
UINT  y 
)
private

Get a pseudo-random tile that matches tiles above and to the left.

Parameters
xIndex of the tile to the left.
yIndex of the tile above.
Returns
Index of a tile that matches tiles above and to the left.

Definition at line 64 of file WangTiler.cpp.

◆ operator()()

const size_t CWangTiler::operator() ( size_t  i,
size_t  j 
) const

Get tile index from m_nTile.

Parameters
iRow number.
jColumn number.
Returns
m_nTile[i][j].

Definition at line 93 of file WangTiler.cpp.

Member Data Documentation

◆ m_nHeight

size_t CWangTiler::m_nHeight = 0
private

Definition at line 42 of file WangTiler.h.

◆ m_nTile

UINT** CWangTiler::m_nTile = nullptr
private

Definition at line 39 of file WangTiler.h.

◆ m_nWidth

size_t CWangTiler::m_nWidth = 0
private

Definition at line 41 of file WangTiler.h.

◆ m_stdRandom

std::default_random_engine CWangTiler::m_stdRandom
private

Definition at line 44 of file WangTiler.h.