Mandelbrot: Add 'Iterations' menu.
This commit is contained in:
parent
84b9e76650
commit
c80973eb36
@ -22,6 +22,7 @@ FractalEngine::FractalEngine(BHandler* parent, BLooper* looper)
|
||||
fMessenger(parent, looper),
|
||||
fBitmapStandby(NULL),
|
||||
fBitmapDisplay(NULL),
|
||||
fIterations(1024),
|
||||
fWidth(0), fHeight(0),
|
||||
fRenderBuffer(NULL),
|
||||
fRenderBufferLen(0),
|
||||
@ -62,6 +63,10 @@ void FractalEngine::MessageReceived(BMessage* msg)
|
||||
case 8: fColorset = Colorset_HighContrast; break;
|
||||
}
|
||||
break;
|
||||
case MSG_SET_ITERATIONS:
|
||||
fIterations = msg->GetUInt16("iterations", 0);
|
||||
break;
|
||||
|
||||
case MSG_RESIZE: {
|
||||
delete fBitmapStandby;
|
||||
// We don't delete the "display" bitmap; the viewer now owns it
|
||||
@ -99,7 +104,6 @@ const double gJuliaA = 0;
|
||||
const double gJuliaB = 1;
|
||||
|
||||
const uint8 gEscapeHorizon = 4;
|
||||
const int32 gIterations = 1024;
|
||||
|
||||
|
||||
void FractalEngine::RenderPixel(uint32 x, uint32 y, double real,
|
||||
@ -127,7 +131,7 @@ int32 FractalEngine::DoSet_Mandelbrot(double real, double imaginary)
|
||||
double zReal = 0;
|
||||
double zImaginary = 0;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
double zRealSq = zReal * zReal;
|
||||
double zImaginarySq = zImaginary * zImaginary;
|
||||
double nzReal = (zRealSq + (-1 * (zImaginarySq)));
|
||||
@ -155,7 +159,7 @@ int32 FractalEngine::DoSet_BurningShip(double real, double imaginary)
|
||||
// It looks "upside down" otherwise.
|
||||
imaginary = -imaginary;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
zReal = fabs(zReal);
|
||||
zImaginary = fabs(zImaginary);
|
||||
|
||||
@ -185,7 +189,7 @@ int32 FractalEngine::DoSet_Tricorn(double real, double imaginary)
|
||||
|
||||
real = -real;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
double znRe = zImaginary * -1;
|
||||
zImaginary = zReal * -1;
|
||||
zReal = znRe; // Swap the real and complex parts each time.
|
||||
@ -217,7 +221,7 @@ int32 FractalEngine::DoSet_Julia(double real, double imaginary)
|
||||
double muRe = gJuliaA;
|
||||
double muIm = gJuliaB;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
double zRealSq = zReal * zReal;
|
||||
double zImaginarySq = zImaginary * zImaginary;
|
||||
double nzReal = (zRealSq + (-1 * (zImaginarySq)));
|
||||
@ -246,7 +250,7 @@ int32 FractalEngine::DoSet_OrbitTrap(double real, double imaginary)
|
||||
double distance = 0;
|
||||
double lineDist = 0;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
double zRealSq = zReal * zReal;
|
||||
double zImaginarySq = zImaginary * zImaginary;
|
||||
double nzReal = (zRealSq + (-1 * (zImaginarySq)));
|
||||
@ -277,7 +281,7 @@ int32 FractalEngine::DoSet_Multibrot(double real, double imaginary)
|
||||
double zReal = 0;
|
||||
double zImaginary = 0;
|
||||
|
||||
for (int32 i = 0; i < gIterations; i++) {
|
||||
for (int32 i = 0; i < fIterations; i++) {
|
||||
double zRealSq = zReal * zReal;
|
||||
double zImaginarySq = zImaginary * zImaginary;
|
||||
double nzReal = (zRealSq * zReal - 3 * zReal * (zImaginarySq));
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
enum {
|
||||
MSG_CHANGE_SET = 'Frct',
|
||||
MSG_SET_PALETTE,
|
||||
MSG_SET_ITERATIONS,
|
||||
MSG_RESIZE,
|
||||
MSG_RENDER,
|
||||
MSG_RENDER_COMPLETE,
|
||||
@ -36,6 +37,7 @@ private:
|
||||
BBitmap* fBitmapStandby;
|
||||
BBitmap* fBitmapDisplay;
|
||||
|
||||
uint16 fIterations;
|
||||
uint16 fWidth;
|
||||
uint16 fHeight;
|
||||
|
||||
|
@ -178,6 +178,14 @@ public:
|
||||
MSG_LIGHTNING_PALETTE,
|
||||
MSG_SPRING_PALETTE,
|
||||
MSG_HIGHCONTRAST_PALETTE,
|
||||
|
||||
MSG_ITER_128,
|
||||
MSG_ITER_512,
|
||||
MSG_ITER_1024,
|
||||
MSG_ITER_4096,
|
||||
MSG_ITER_8192,
|
||||
MSG_ITER_12288,
|
||||
MSG_ITER_16384
|
||||
};
|
||||
MandelbrotWindow(BRect frame);
|
||||
~MandelbrotWindow() {}
|
||||
@ -201,6 +209,7 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
|
||||
BMenuBar* menuBar = new BMenuBar("MenuBar");
|
||||
BMenu* setMenu;
|
||||
BMenu* paletteMenu;
|
||||
BMenu* iterMenu;
|
||||
BLayoutBuilder::Menu<>(menuBar)
|
||||
.AddMenu(B_TRANSLATE("File"))
|
||||
.AddItem(B_TRANSLATE("Quit"), B_QUIT_REQUESTED, 'Q')
|
||||
@ -226,11 +235,23 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
|
||||
.AddItem(B_TRANSLATE("Spring"), MSG_SPRING_PALETTE)
|
||||
.AddItem(B_TRANSLATE("High contrast"), MSG_HIGHCONTRAST_PALETTE)
|
||||
.End()
|
||||
.AddMenu(B_TRANSLATE("Iterations"))
|
||||
.GetMenu(iterMenu)
|
||||
.AddItem("128", MSG_ITER_128)
|
||||
.AddItem("512", MSG_ITER_512)
|
||||
.AddItem("1024", MSG_ITER_1024)
|
||||
.AddItem("4096", MSG_ITER_4096)
|
||||
.AddItem("8192", MSG_ITER_8192)
|
||||
.AddItem("12288", MSG_ITER_12288)
|
||||
.AddItem("16384", MSG_ITER_16384)
|
||||
.End()
|
||||
.End();
|
||||
setMenu->SetRadioMode(true);
|
||||
setMenu->FindItem(MSG_MANDELBROT_SET)->SetMarked(true);
|
||||
paletteMenu->SetRadioMode(true);
|
||||
paletteMenu->FindItem(MSG_ROYAL_PALETTE)->SetMarked(true);
|
||||
iterMenu->SetRadioMode(true);
|
||||
iterMenu->FindItem(MSG_ITER_1024)->SetMarked(true);
|
||||
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||
.SetInsets(0)
|
||||
@ -256,6 +277,14 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
|
||||
fFractalView->RedrawFractal(); \
|
||||
break; \
|
||||
}
|
||||
#define HANDLE_ITER(uiwhat, id) \
|
||||
case uiwhat: { \
|
||||
BMessage msg(FractalEngine::MSG_SET_ITERATIONS); \
|
||||
msg.AddUInt16("iterations", id); \
|
||||
fFractalView->fFractalEngine->PostMessage(&msg); \
|
||||
fFractalView->RedrawFractal(); \
|
||||
break; \
|
||||
}
|
||||
void
|
||||
MandelbrotWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
@ -277,6 +306,14 @@ MandelbrotWindow::MessageReceived(BMessage* msg)
|
||||
HANDLE_PALETTE(MSG_SPRING_PALETTE, 7)
|
||||
HANDLE_PALETTE(MSG_HIGHCONTRAST_PALETTE, 8)
|
||||
|
||||
HANDLE_ITER(MSG_ITER_128, 128)
|
||||
HANDLE_ITER(MSG_ITER_512, 512)
|
||||
HANDLE_ITER(MSG_ITER_1024, 1024)
|
||||
HANDLE_ITER(MSG_ITER_4096, 4096)
|
||||
HANDLE_ITER(MSG_ITER_8192, 8192)
|
||||
HANDLE_ITER(MSG_ITER_12288, 12288)
|
||||
HANDLE_ITER(MSG_ITER_16384, 16384)
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
break;
|
||||
@ -284,6 +321,7 @@ MandelbrotWindow::MessageReceived(BMessage* msg)
|
||||
}
|
||||
#undef HANDLE_SET
|
||||
#undef HANDLE_PALETTE
|
||||
#undef HANDLE_ITER
|
||||
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user