Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27470 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -49,15 +49,16 @@ hack doesn't fix.
|
|||||||
#define Random(x) (rand() % x)
|
#define Random(x) (rand() % x)
|
||||||
#define Randomize() (srand((unsigned int)time(NULL)))
|
#define Randomize() (srand((unsigned int)time(NULL)))
|
||||||
|
|
||||||
static int detail = 9; // CHANGE THIS... 7,8,9 etc
|
static int detail = 9; // CHANGE THIS... 7,8,9 etc
|
||||||
|
|
||||||
static bool running = FALSE;
|
static bool running = false;
|
||||||
static wxMenuBar *menuBar = NULL;
|
static wxMenuBar *menuBar = NULL;
|
||||||
|
|
||||||
// Define a new application type
|
// Define a new application type
|
||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{ public:
|
{
|
||||||
bool OnInit();
|
public:
|
||||||
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
@@ -66,26 +67,27 @@ IMPLEMENT_APP(MyApp)
|
|||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
|
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||||
|
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new canvas which can receive some events
|
// Define a new canvas which can receive some events
|
||||||
class MyCanvas: public wxWindow
|
class MyCanvas: public wxWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCanvas(wxFrame *frame);
|
MyCanvas(wxFrame *frame);
|
||||||
void Draw(wxDC& dc);
|
void Draw(wxDC& dc);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnPaint(wxPaintEvent& event);
|
void OnPaint(wxPaintEvent& event);
|
||||||
void Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio);
|
void Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio);
|
||||||
wxPen SnowPen, MtnPen, GreenPen;
|
wxPen SnowPen, MtnPen, GreenPen;
|
||||||
wxBrush WaterBrush;
|
wxBrush WaterBrush;
|
||||||
int Sealevel;
|
int Sealevel;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
@@ -94,7 +96,7 @@ DECLARE_EVENT_TABLE()
|
|||||||
bool MyApp::OnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
// Create the main frame window
|
// Create the main frame window
|
||||||
MyFrame *frame = new MyFrame(NULL, _T("Fractal Mountains for wxWidgets"), wxPoint(-1, -1), wxSize(640, 480));
|
MyFrame *frame = new MyFrame(NULL, _T("Fractal Mountains for wxWidgets"), wxDefaultPosition, wxSize(640, 480));
|
||||||
|
|
||||||
// Make a menubar
|
// Make a menubar
|
||||||
wxMenu *file_menu = new wxMenu;
|
wxMenu *file_menu = new wxMenu;
|
||||||
@@ -109,9 +111,9 @@ bool MyApp::OnInit()
|
|||||||
(void) new MyCanvas(frame);
|
(void) new MyCanvas(frame);
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(TRUE);
|
frame->Show(true);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
@@ -121,7 +123,7 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
|
||||||
wxFrame(frame, -1, title, pos, size, wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE)
|
wxFrame(frame, wxID_ANY, title, pos, size, wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,13 +135,13 @@ void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
static bool destroyed = FALSE;
|
static bool destroyed = false;
|
||||||
if (destroyed)
|
if (destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->Destroy();
|
this->Destroy();
|
||||||
|
|
||||||
destroyed = TRUE;
|
destroyed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyCanvas, wxWindow)
|
BEGIN_EVENT_TABLE(MyCanvas, wxWindow)
|
||||||
@@ -148,7 +150,7 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
// Define a constructor for my canvas
|
// Define a constructor for my canvas
|
||||||
MyCanvas::MyCanvas(wxFrame *frame):
|
MyCanvas::MyCanvas(wxFrame *frame):
|
||||||
wxWindow(frame, -1)
|
wxWindow(frame, wxID_ANY)
|
||||||
{
|
{
|
||||||
wxColour wxCol1(255,255,255);
|
wxColour wxCol1(255,255,255);
|
||||||
SnowPen = wxPen(wxCol1, 2, wxSOLID);
|
SnowPen = wxPen(wxCol1, 2, wxSOLID);
|
||||||
@@ -166,90 +168,94 @@ MyCanvas::MyCanvas(wxFrame *frame):
|
|||||||
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
Draw(dc);
|
PrepareDC(dc);
|
||||||
|
Draw(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCanvas::Draw(wxDC& dc)
|
void MyCanvas::Draw(wxDC& dc)
|
||||||
{
|
{
|
||||||
if (running) return;
|
if (running) return;
|
||||||
|
|
||||||
running = TRUE;
|
running = true;
|
||||||
menuBar->EnableTop(0, FALSE);
|
menuBar->EnableTop(0, false);
|
||||||
|
|
||||||
Randomize();
|
Randomize();
|
||||||
|
|
||||||
int Left, Top, Right, Bottom;
|
dc.SetBackground(*wxLIGHT_GREY_BRUSH);
|
||||||
GetClientSize(&Right, &Bottom);
|
dc.Clear();
|
||||||
|
|
||||||
Right *= 3; Right /= 4;
|
int Left, Top, Right, Bottom;
|
||||||
Bottom *= 3; Bottom /= 4;
|
GetClientSize(&Right, &Bottom);
|
||||||
Left = 0;
|
|
||||||
Top = Bottom/8;
|
|
||||||
|
|
||||||
wxPoint Water[4];
|
Right *= 3; Right /= 4;
|
||||||
Water[0].x = Left; Water[0].y = Top;
|
Bottom *= 3; Bottom /= 4;
|
||||||
Water[1].x = Right; Water[1].y = Top;
|
Left = 0;
|
||||||
Water[2].x = Right+Bottom/2; Water[2].y = Bottom;
|
Top = Bottom/8;
|
||||||
Water[3].x = Bottom/2; Water[3].y = Bottom;
|
|
||||||
|
|
||||||
dc.SetBrush(WaterBrush);
|
wxPoint Water[4];
|
||||||
dc.DrawPolygon(4, Water);
|
Water[0].x = Left; Water[0].y = Top;
|
||||||
|
Water[1].x = Right; Water[1].y = Top;
|
||||||
|
Water[2].x = Right+Bottom/2; Water[2].y = Bottom;
|
||||||
|
Water[3].x = Bottom/2; Water[3].y = Bottom;
|
||||||
|
|
||||||
double H = 0.75;
|
dc.SetBrush(WaterBrush);
|
||||||
double Scale = Bottom;
|
dc.DrawPolygon(4, Water);
|
||||||
double Ratio = 1.0 / pow(2.0, H);
|
|
||||||
double Std = Scale * Ratio;
|
|
||||||
Sealevel = Random(18) - 8;
|
|
||||||
|
|
||||||
Fractal(dc, Left, Top, Right, Bottom, 0, 0, 0, 0, detail, Std, Ratio);
|
double H = 0.75;
|
||||||
|
double Scale = Bottom;
|
||||||
|
double Ratio = 1.0 / pow(2.0, H);
|
||||||
|
double Std = Scale * Ratio;
|
||||||
|
Sealevel = Random(18) - 8;
|
||||||
|
|
||||||
menuBar->EnableTop(0, TRUE);
|
Fractal(dc, Left, Top, Right, Bottom, 0, 0, 0, 0, detail, Std, Ratio);
|
||||||
running = FALSE;
|
|
||||||
|
menuBar->EnableTop(0, true);
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCanvas::Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio)
|
void MyCanvas::Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio)
|
||||||
{
|
{
|
||||||
int Xmid = (X1 + X2) / 2;
|
int Xmid = (X1 + X2) / 2;
|
||||||
int Ymid = (Y1 + Y2) / 2;
|
int Ymid = (Y1 + Y2) / 2;
|
||||||
int Z23 = (Z2 + Z3) / 2;
|
int Z23 = (Z2 + Z3) / 2;
|
||||||
int Z41 = (Z4 + Z1) / 2;
|
int Z41 = (Z4 + Z1) / 2;
|
||||||
int Newz = (int)((Z1 + Z2 + Z3 + Z4) / 4 + (double)(Random(17) - 8) / 8.0 * Std);
|
int Newz = (int)((Z1 + Z2 + Z3 + Z4) / 4 + (double)(Random(17) - 8) / 8.0 * Std);
|
||||||
|
|
||||||
if (--Iteration)
|
if (--Iteration)
|
||||||
{
|
{
|
||||||
int Z12 = (Z1 + Z2) / 2;
|
int Z12 = (Z1 + Z2) / 2;
|
||||||
int Z34 = (Z3 + Z4) / 2;
|
int Z34 = (Z3 + Z4) / 2;
|
||||||
double Stdmid = Std * Ratio;
|
double Stdmid = Std * Ratio;
|
||||||
|
|
||||||
Fractal(dc, Xmid, Y1, X2, Ymid, Z12, Z2, Z23, Newz, Iteration, Stdmid, Ratio);
|
Fractal(dc, Xmid, Y1, X2, Ymid, Z12, Z2, Z23, Newz, Iteration, Stdmid, Ratio);
|
||||||
Fractal(dc, X1, Y1, Xmid, Ymid, Z1, Z12, Newz, Z41, Iteration, Stdmid, Ratio);
|
Fractal(dc, X1, Y1, Xmid, Ymid, Z1, Z12, Newz, Z41, Iteration, Stdmid, Ratio);
|
||||||
Fractal(dc, Xmid, Ymid, X2, Y2, Newz, Z23, Z3, Z34, Iteration, Stdmid, Ratio);
|
Fractal(dc, Xmid, Ymid, X2, Y2, Newz, Z23, Z3, Z34, Iteration, Stdmid, Ratio);
|
||||||
Fractal(dc, X1, Ymid, Xmid, Y2, Z41, Newz, Z34, Z4, Iteration, Stdmid, Ratio);
|
Fractal(dc, X1, Ymid, Xmid, Y2, Z41, Newz, Z34, Z4, Iteration, Stdmid, Ratio);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Newz <= Sealevel)
|
if (Newz <= Sealevel)
|
||||||
{
|
{
|
||||||
wxPoint P[4];
|
wxPoint P[4];
|
||||||
P[0].x = Y1 / 2 + X1; P[0].y = Y1 + Z1;
|
P[0].x = Y1 / 2 + X1; P[0].y = Y1 + Z1;
|
||||||
P[1].x = Y1 / 2 + X2; P[1].y = Y1 + Z2;
|
P[1].x = Y1 / 2 + X2; P[1].y = Y1 + Z2;
|
||||||
P[2].x = Y2 / 2 + X2; P[2].y = Y2 + Z3;
|
P[2].x = Y2 / 2 + X2; P[2].y = Y2 + Z3;
|
||||||
P[3].x = Y2 / 2 + X1; P[3].y = Y2 + Z4;
|
P[3].x = Y2 / 2 + X1; P[3].y = Y2 + Z4;
|
||||||
|
|
||||||
dc.SetPen(* wxBLACK_PEN);
|
dc.SetPen(* wxBLACK_PEN);
|
||||||
dc.SetBrush(* wxBLACK_BRUSH);
|
dc.SetBrush(* wxBLACK_BRUSH);
|
||||||
|
|
||||||
dc.DrawPolygon(4, P);
|
dc.DrawPolygon(4, P);
|
||||||
|
|
||||||
if (Z1 >= -(60+Random(25)))
|
if (Z1 >= -(60+Random(25)))
|
||||||
dc.SetPen(GreenPen);
|
dc.SetPen(GreenPen);
|
||||||
else if (Z1 >= -(100+Random(25)))
|
else if (Z1 >= -(100+Random(25)))
|
||||||
dc.SetPen(MtnPen);
|
dc.SetPen(MtnPen);
|
||||||
else
|
else
|
||||||
dc.SetPen(SnowPen);
|
dc.SetPen(SnowPen);
|
||||||
|
|
||||||
dc.DrawLine(Ymid/2+X2, Ymid+Z23, Ymid/2+X1, Ymid+Z41);
|
dc.DrawLine(Ymid/2+X2, Ymid+Z23, Ymid/2+X1, Ymid+Z41);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user