38#pragma region Constructors and destructors
57#pragma endregion Constructors and destructors
62#pragma region Drawing functions
69 HDC hdc = BeginPaint(
m_hWnd, &ps);
70 Gdiplus::Graphics graphics(hdc);
74 const int nBitmapWidth =
m_pBitmap->GetWidth();
75 const int nBitmapHeight =
m_pBitmap->GetHeight();
80 GetClientRect(
m_hWnd, &rectClient);
81 const int nClientWidth = rectClient.right - rectClient.left;
82 const int nClientHeight = rectClient.bottom - rectClient.top;
86 const int nDestSide = min(nClientWidth, nClientHeight);
88 const int width = min(nDestSide, nBitmapWidth);
89 const int height = min(nDestSide, nBitmapHeight);
91 const int x = max(0, nClientWidth - width)/2;
92 const int y = max(0, nClientHeight - height)/2;
94 Gdiplus::Rect rectDest(x, y, width, height);
103#pragma endregion Drawing functions
108#pragma region Menu functions
113 HMENU hMenubar = CreateMenu();
124 SetMenu(
m_hWnd, hMenubar);
164#pragma endregion Menu functions
169#pragma region Bitmap functions
197 SetPixel(i, j, BYTE(
float(0xFF)*(g/2 + 0.5f)));
208 SetPixel(i, j, Gdiplus::Color(255, b, b, b));
221#pragma endregion Bitmap functions
226#pragma region Noise generation functions
244 for(UINT i=0; i<w; i++){
247 for(UINT j=0; j<h; j++){
274 const UINT nLeft = (UINT)floorf(rect.GetLeft() + point.X);
275 const UINT nRight = (UINT)ceilf(rect.GetRight() + point.X);
276 const UINT nTop = (UINT)floorf(rect.GetTop() + point.Y);
277 const UINT nBottom = (UINT)ceilf(rect.GetBottom() + point.Y);
279 for(UINT i=nLeft; i<nRight; i++){
282 for(UINT j=nTop; j<nBottom; j++){
298 Gdiplus::FontFamily ff(L
"Arial");
299 Gdiplus::Font font(&ff, 20, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
300 Gdiplus::SolidBrush brush(Gdiplus::Color::White);
306 Gdiplus::PointF point(0.0f, 0.0f);
308 std::wstring wstr = L
"(";
309 wstr += std::to_wstring((
size_t)floorf(
m_fOriginX)) + L
", ";
310 wstr += std::to_wstring((
size_t)floorf(
m_fOriginY)) + L
")";
312 Gdiplus::RectF rect, unused;
313 graphics.MeasureString(wstr.c_str(), -1, &font, unused, &rect);
316 graphics.DrawString(wstr.c_str(), -1, &font, point, &brush);
326 graphics.MeasureString(wstr.c_str(), -1, &font, unused, &rect);
327 point.X =
m_pBitmap->GetWidth() - rect.Width;
328 point.Y =
m_pBitmap->GetHeight() - rect.Height;
331 graphics.DrawString(wstr.c_str(), -1, &font, point, &brush);
345 const float fBitmapWidth = (float)
m_pBitmap->GetWidth();
346 const float fBitmapHeight = (float)
m_pBitmap->GetHeight();
348 const UINT nv = (UINT)floorf(fBitmapWidth/
m_fScale);
349 const UINT nh = (UINT)floorf(fBitmapHeight/
m_fScale);
352 Gdiplus::Pen pen(Gdiplus::Color(255, 0, 255, 0));
356 Gdiplus::PointF left(0.0f,
m_fScale);
357 Gdiplus::PointF right(fBitmapWidth,
m_fScale);
358 Gdiplus::RectF rect(0.0f, 0.0f, fBitmapWidth, 1.0f);
360 for(UINT i=0; i<nh; i++){
361 if(
m_bShowGrid)graphics.DrawLine(&pen, left, right);
371 Gdiplus::PointF top(
m_fScale, 0.0f);
372 Gdiplus::PointF bottom(
m_fScale, fBitmapHeight);
373 rect = Gdiplus::RectF(0.0f, 0.0f, 1.0f, fBitmapHeight);
375 for(UINT i=0; i<nv; i++){
376 if(
m_bShowGrid)graphics.DrawLine(&pen, top, bottom);
395#pragma endregion Noise generation functions
400#pragma region Menu response functions
549#pragma endregion Menu response functions
554#pragma region Reader functions
563 case eNoise::Perlin: wstr = L
"Perlin";
break;
564 case eNoise::Value: wstr = L
"Value";
break;
568 case eHash::Permutation: wstr += L
"-Perm";
break;
569 case eHash::LinearCongruential: wstr += L
"-Lin";
break;
570 case eHash::Std: wstr += L
"-Std";
break;
574 case eDistribution::Uniform:
break;
575 case eDistribution::Maximal: wstr += L
"-Max";
break;
576 case eDistribution::Cosine: wstr += L
"-Cos";
break;
577 case eDistribution::Normal: wstr += L
"-Norm";
break;
578 case eDistribution::Exponential: wstr += L
"-Exp";
break;
579 case eDistribution::Midpoint: wstr += L
"-Mid";
break;
583 case eSpline::None: wstr += L
"-NoSpline";
break;
584 case eSpline::Cubic:
break;
585 case eSpline::Quintic: wstr += L
"-Quintic";
break;
590 wstr += L
"-" + std::to_wstring((
size_t)round(
m_fScale));
604 wstr += std::to_wstring(
m_nOctaves) + L
" octave";
612 case eNoise::Perlin: wstr += L
"Perlin";
break;
613 case eNoise::Value: wstr += L
"Value";
break;
620 wstr += L
" with origin (";
627 case eHash::Permutation: wstr += L
"a permutation";
break;
628 case eHash::LinearCongruential: wstr += L
"linear congruential";
break;
629 case eHash::Std: wstr += L
"std";
break;
632 wstr += L
" hash function, ";
637 case eDistribution::Uniform: wstr += L
"uniform";
break;
638 case eDistribution::Maximal: wstr += L
"maximal";
break;
639 case eDistribution::Cosine: wstr += L
"cosine";
break;
640 case eDistribution::Normal: wstr += L
"normal";
break;
641 case eDistribution::Exponential: wstr += L
"exponential";
break;
642 case eDistribution::Midpoint: wstr += L
"midpoint displacement";
break;
646 case eNoise::Perlin: wstr += L
" gradient";
break;
647 case eNoise::Value: wstr += L
" height";
break;
650 wstr += L
" distribution, ";
655 case eSpline::None: wstr += L
"no";
break;
656 case eSpline::Cubic: wstr += L
"cubic";
break;
657 case eSpline::Quintic: wstr += L
"quintic";
break;
660 wstr += L
" spline function, ";
664 wstr += L
"scale " + std::to_wstring((
size_t)round(
m_fScale)) + L
", and ";
669 wstr += L
"permutation and ";
672 case eNoise::Perlin: wstr += L
"gradient ";
break;
673 case eNoise::Value: wstr += L
"value ";
break;
676 wstr += L
"table size ";
682 wstr += L
"Largest generated noise ";
684 wstr += L
"Smallest generated noise ";
686 wstr += L
"Average generated noise ";
699#pragma endregion Reader functions
Interface for the main class CMain.
Useful defines, constants, and types.
eDistribution
Distribution.
std::wstring to_wstring_f(float x, size_t n)
Float to fixed precision wstring.
Interface for helper functions.
HMENU CreateViewMenu(HMENU hMenubar)
Create View menu.
void UpdateGenerateMenu(HMENU hMenu, eNoise noise)
Update Generate menu.
HMENU CreateSplineMenu(HMENU hMenubar)
Create Spline menu.
HMENU CreateHashMenu(HMENU hMenubar)
Create Hash menu.
void UpdateHashMenu(HMENU hMenu, eNoise noise, eHash h)
Update Hash menu.
void UpdateViewMenu(HMENU hMenu, eNoise noise)
Update View menu.
HMENU CreateDistributionMenu(HMENU hMenubar)
Create Distribution menu.
void UpdateSettingsMenu(HMENU hMenu, eNoise noise)
Update Settings menu.
HMENU CreateSettingsMenu(HMENU hMenubar)
Create Settings menu.
void UpdateSplineMenu(HMENU hMenu, eNoise noise, eSpline spline)
Update Spline menu.
void UpdateMenuItemGray(HMENU hMenu, UINT item, eNoise noise, bool bGray)
Update menu item bool.
ULONG_PTR InitGDIPlus()
Initialize GDI+.
void UpdateFileMenu(HMENU hMenu, eNoise noise)
Update File menu.
HMENU CreateFileMenu(HMENU hMenubar)
Create File menu.
void UpdateDistributionMenu(HMENU hMenu, eNoise noise, eDistribution distr)
Update Distribution menu.
void UpdateMenuItemCheck(HMENU hMenu, UINT item, bool bCheck)
Update menu item check.
void CreateHelpMenu(HMENU hMenubar)
Create Help menu.
HMENU CreateGenerateMenu(HMENU hMenubar)
Create Generate menu.
Interface for some helpful Windows-specific functions.
#define IDM_SETTINGS_TSIZE_UP
Menu id for table size up.
#define IDM_VIEW_GRID
Menu id for view grid.
#define IDM_SETTINGS_SCALE_UP
Menu id for scale up.
#define IDM_SETTINGS_SCALE_DN
Menu id for scale down.
#define IDM_SETTINGS_RESET
Menu id for reset settings.
#define IDM_SETTINGS_TSIZE_DN
Menu id for table size down.
void UpdateMenuItem(HMENU hMenu, UINT up, UINT dn, eNoise noise, t n, t nMin, t nMax)
Update a numeric menu item.
#define IDM_SETTINGS_OCTAVE_UP
Menu id for octave up.
#define IDM_SETTINGS_OCTAVE_DN
Menu id for octave down.
#define IDM_VIEW_COORDS
Menu id for view coordinates.
#define IDM_GENERATE_RESETORIGIN
Menu id for reset origin.
void ClearBitmap(Gdiplus::Color)
Clear bitmap to color.
CPerlinNoise2D * m_pPerlin
Pointer to Perlin noise generator.
HMENU m_hGenMenu
Handle to the Generate menu.
const std::wstring GetNoiseDescription() const
Get noise description.
void CreateMenus()
Create menus.
HMENU m_hSplineMenu
Handle to the Spline menu.
void DecreaseScale()
Decrease scale.
HMENU m_hDistMenu
Handle to the Distribution menu.
void GenerateNoiseBitmap()
Generate bitmap again with saved parameters.
void DrawGrid()
Draw grid to bitmap.
eNoise m_eNoise
Noise type.
bool m_bShowCoords
Show coordinates flag.
const float m_fMaxScale
Minimum scale.
const std::wstring GetFileName() const
Get noise file name.
const size_t m_nMaxOctaves
Maximum number of octaves of noise.
HMENU m_hFileMenu
Handle to the File menu.
void CreateBitmap(int w, int h)
Create bitmap.
void Randomize()
Randomize PRNG.
float m_fMax
Largest noise value in generated noise.
void Reset()
Reset number of octaves, scale, table size.
void UpdateMenus()
Update menus.
void DrawCoords()
Draw coordinates to bitmap.
bool SetDistribution(eDistribution)
Set probability distribution.
HMENU m_hHashMenu
Handle to the Hash menu.
void DecreaseTableSize()
Decrease table size.
float m_fAve
Average noise value in generated noise.
float m_fOriginX
X-coordinate of top.
CMain(const HWND hwnd)
Constructor.
void ToggleViewCoords()
Toggle View Coordinates flag.
float m_fOriginY
Y-coordinate of left.
const size_t m_nMinOctaves
Minimum number of octaves of noise.
void IncreaseTableSize()
Increase table size.
const size_t m_nDefOctaves
Default number of octaves of noise.
ULONG_PTR m_gdiplusToken
GDI+ token.
Gdiplus::Bitmap * GetBitmap() const
Get pointer to bitmap.
const float m_fMinScale
Minimum scale.
void SetHash(eHash)
Set hash function.
void DecreaseOctaves()
Decrease number of octaves.
void Jump()
Change origin coordinates.
HMENU m_hViewMenu
Handle to the View menu.
bool m_bShowGrid
Show grid flag.
void ToggleViewGrid()
Toggle View Grid flag.
HMENU m_hSetMenu
Handle to the Settings menu.
void SetSpline(eSpline)
Set spline function.
void IncreaseOctaves()
Increase number of octaves.
const bool Origin(float x, float y) const
Check origin coordinates.
Gdiplus::Bitmap * m_pBitmap
Pointer to a bitmap image.
void OnPaint()
Paint the client area of the window.
size_t m_nOctaves
Number of octaves of noise.
const float m_fDefScale
Default scale.
void SetPixel(UINT, UINT, float)
Set pixel grayscale from float.
void IncreaseScale()
Increase scale.
HWND m_hWnd
Window handle.
float m_fMin
Smallest noise value in generated noise.
2D Perlin and Value noise generator.
const size_t GetMinTableSize() const
Get minimum table size.
const eSpline GetSpline() const
Get spline function type.
void SetHash(eHash)
Set hash function.
const size_t GetMaxTableSize() const
Get maximum table size.
const size_t GetTableSize() const
Get table size.
bool DefaultTableSize()
Set table size to default.
void SetSpline(eSpline)
Set spline function.
const float generate(float, float, eNoise, size_t, float=0.5f, float=2.0f) const
Generate noise at a point.
void RandomizeTable(eDistribution)
Randomize table from distribution.
const eHash GetHash() const
Get hash function type.
bool DoubleTableSize()
Double table size.
const eDistribution GetDistribution() const
Get distribution type.
bool HalveTableSize()
Halve table size.
const size_t GetDefTableSize() const
Get default table size.
void SetSeed()
Set seed for PRNG.
Interface for the Perlin and Value noise generators.