Smooth 2D Noise Viewer
Perlin and Value Noise
|
The main class. More...
#include <CMain.h>
Public Member Functions | |
CMain (const HWND hwnd) | |
Constructor. More... | |
~CMain () | |
Destructor. More... | |
void | CreateBitmap (int w, int h) |
Create bitmap. More... | |
void | ClearBitmap (Gdiplus::Color) |
Clear bitmap to color. More... | |
void | Randomize () |
Randomize PRNG. More... | |
void | GenerateNoiseBitmap (eNoise) |
Generate Perlin or Value noise bitmap. More... | |
void | GenerateNoiseBitmap () |
Generate bitmap again with saved parameters. More... | |
bool | SetDistribution (eDistribution) |
Set probability distribution. More... | |
void | SetSpline (eSpline) |
Set spline function. More... | |
void | SetHash (eHash) |
Set hash function. More... | |
void | ToggleViewCoords () |
Toggle View Coordinates flag. More... | |
void | ToggleViewGrid () |
Toggle View Grid flag. More... | |
void | Jump () |
Change origin coordinates. More... | |
void | Jump (float x, float y) |
Change origin coordinates. More... | |
const bool | Origin (float x, float y) const |
Check origin coordinates. More... | |
void | IncreaseOctaves () |
Increase number of octaves. More... | |
void | DecreaseOctaves () |
Decrease number of octaves. More... | |
void | IncreaseScale () |
Increase scale. More... | |
void | DecreaseScale () |
Decrease scale. More... | |
void | IncreaseTableSize () |
Increase table size. More... | |
void | DecreaseTableSize () |
Decrease table size. More... | |
void | Reset () |
Reset number of octaves, scale, table size. More... | |
void | OnPaint () |
Paint the client area of the window. More... | |
Gdiplus::Bitmap * | GetBitmap () const |
Get pointer to bitmap. More... | |
const std::wstring | GetFileName () const |
Get noise file name. More... | |
const std::wstring | GetNoiseDescription () const |
Get noise description. More... | |
Private Member Functions | |
void | CreateMenus () |
Create menus. More... | |
void | UpdateMenus () |
Update menus. More... | |
void | SetPixel (UINT, UINT, float) |
Set pixel grayscale from float. More... | |
void | SetPixel (UINT, UINT, BYTE) |
Set pixel grayscale from byte. More... | |
void | SetPixel (UINT, UINT, Gdiplus::Color) |
Set pixel from GDI+ color. More... | |
void | DrawCoords () |
Draw coordinates to bitmap. More... | |
void | DrawGrid () |
Draw grid to bitmap. More... | |
void | GenerateNoiseBitmap (Gdiplus::PointF, Gdiplus::RectF) |
Generate bitmap rectangle. More... | |
Private Attributes | |
HWND | m_hWnd = nullptr |
Window handle. More... | |
HMENU | m_hFileMenu = nullptr |
Handle to the File menu. More... | |
HMENU | m_hGenMenu = nullptr |
Handle to the Generate menu. More... | |
HMENU | m_hViewMenu = nullptr |
Handle to the View menu. More... | |
HMENU | m_hSetMenu = nullptr |
Handle to the Settings menu. More... | |
HMENU | m_hDistMenu = nullptr |
Handle to the Distribution menu. More... | |
HMENU | m_hHashMenu = nullptr |
Handle to the Hash menu. More... | |
HMENU | m_hSplineMenu = nullptr |
Handle to the Spline menu. More... | |
HMENU | m_hOctaveMenu = nullptr |
Handle to the Octave menu. More... | |
eNoise | m_eNoise = eNoise::None |
Noise type. More... | |
float | m_fOriginX = 0.0f |
X-coordinate of top. More... | |
float | m_fOriginY = 0.0f |
Y-coordinate of left. More... | |
const size_t | m_nDefOctaves = 4 |
Default number of octaves of noise. More... | |
size_t | m_nOctaves = m_nDefOctaves |
Number of octaves of noise. More... | |
const size_t | m_nMinOctaves = 1 |
Minimum number of octaves of noise. More... | |
const size_t | m_nMaxOctaves = 8 |
Maximum number of octaves of noise. More... | |
const float | m_fDefScale = 64.0f |
Default scale. More... | |
float | m_fScale = m_fDefScale |
Scale. More... | |
const float | m_fMinScale = 8.0f |
Minimum scale. More... | |
const float | m_fMaxScale = 512.0f |
Minimum scale. More... | |
float | m_fMin = 0.0f |
Smallest noise value in generated noise. More... | |
float | m_fMax = 0.0f |
Largest noise value in generated noise. More... | |
float | m_fAve = 0.0f |
Average noise value in generated noise. More... | |
ULONG_PTR | m_gdiplusToken = 0 |
GDI+ token. More... | |
Gdiplus::Bitmap * | m_pBitmap = nullptr |
Pointer to a bitmap image. More... | |
CPerlinNoise2D * | m_pPerlin = nullptr |
Pointer to Perlin noise generator. More... | |
bool | m_bShowCoords = false |
Show coordinates flag. More... | |
bool | m_bShowGrid = false |
Show grid flag. More... | |
The interface between I/O from Windows (input from the drop-down menus, output to the client area of the window), the noise generator, and the GDI+ graphics interface. This class maintains a single GDI+ bitmap to which all noise and related elements (coordinates, grids) are drawn.
CMain::CMain | ( | const HWND | hwnd | ) |
CMain::~CMain | ( | ) |
void CMain::ClearBitmap | ( | Gdiplus::Color | clr | ) |
void CMain::CreateBitmap | ( | int | w, |
int | h | ||
) |
|
private |
void CMain::DecreaseOctaves | ( | ) |
void CMain::DecreaseScale | ( | ) |
void CMain::DecreaseTableSize | ( | ) |
|
private |
If m_bShowCoords
is true
, then draw the coordinates of the top left and bottom right of the noise to the corresponding corners of the bitmap. The font family, font, style, and color of the text are hard-coded. If m_bShowCoords
is false
, then overwrite the pixels within the bounding rectangle of the text coordinates with the corresponding noise. This enables us to remove the coordinate text from the bitmap without having to regenerate the whole bitmap.
|
private |
If m_bShowGrid
is true
, draw a grid for first noise octave to the bitmap. The line color for the grid is fixed. If m_bShowGrid
is false
, then overwrite the pixels in the lines with the corresponding noise. This enables us to remove the grid lines from the bitmap without having to regenerate the whole bitmap.
void CMain::GenerateNoiseBitmap | ( | ) |
void CMain::GenerateNoiseBitmap | ( | eNoise | t | ) |
|
private |
Generate Perlin or Value noise into a rectangle in the bitmap. This is the cool thing about Perlin noise - the noise value at each point is computed independently of all the other points. We will use this to quickly remove the grid and/or the coordinate text from the bitmap without having to recompute noise values for the whole bitmap.
point | The position of the rectangle to be written in the bitmap. |
rect | The bounds of the rectangle to be written in the bitmap. |
Gdiplus::Bitmap * CMain::GetBitmap | ( | ) | const |
const std::wstring CMain::GetFileName | ( | ) | const |
const std::wstring CMain::GetNoiseDescription | ( | ) | const |
void CMain::IncreaseOctaves | ( | ) |
void CMain::IncreaseScale | ( | ) |
void CMain::IncreaseTableSize | ( | ) |
void CMain::Jump | ( | ) |
void CMain::Jump | ( | float | x, |
float | y | ||
) |
void CMain::OnPaint | ( | ) |
const bool CMain::Origin | ( | float | x, |
float | y | ||
) | const |
void CMain::Randomize | ( | ) |
void CMain::Reset | ( | ) |
bool CMain::SetDistribution | ( | eDistribution | d | ) |
void CMain::SetHash | ( | eHash | d | ) |
|
private |
Set a grayscale pixel in the bitmap from a byte value in the range \([0, 255]\), where \(0\) is black and \(255\) is white. The indices of the pixel are assumed to be in range.
i | Row number. |
j | Column number. |
b | Grayscale value in the range \([0, 255]\). |
|
private |
Set a grayscale pixel in the bitmap from a floating point value in \([-1, 1]\), where \(-1\) is black and \(+1\) is white. The indices of the pixel are assumed to be in range.
i | Row number. |
j | Column number. |
g | Grayscale value in the range \([-1, 1]\). |
|
private |
void CMain::SetSpline | ( | eSpline | d | ) |
void CMain::ToggleViewCoords | ( | ) |
void CMain::ToggleViewGrid | ( | ) |
|
private |
|
private |
|
private |
|
private |