Using TExec to handle keyboard events and TComplex to draw the Mandelbrot set.
Pressing the keys 'z' and 'u' will zoom and unzoom the picture near the mouse location, 'r' will reset to the default view.
Try it (in compiled mode!) with: root mandelbrot.C+
Details
when a mouse event occurs the myexec() function is called (by using AddExec). Depending on the pressed key, the mygenerate() function is called, with the proper arguments. Note the last_x and last_y variables that are used in myexec() to store the last pointer coordinates (px is not a pointer position in kKeyPress events).
{
if (factor > 0) {
} else {
last_histo =
new TH2F(
"h2",
"Mandelbrot [move mouse and press z to zoom, u to unzoom, r to reset]", 200, -2, 2,
200, -2, 2);
}
int iter = 0;
z = z * z + point;
iter++;
break;
}
}
}
{
int event =
gPad->GetEvent();
int px =
gPad->GetEventX();
int py =
gPad->GetEventY();
double xd =
gPad->AbsPixeltoX(px);
double yd =
gPad->AbsPixeltoY(py);
return;
}
const double Z = 2.;
switch (px) {
case 'z':
break;
case 'u':
break;
case 'r':
break;
};
}
{
new TCanvas(
"canvas",
"View Mandelbrot set");
gPad->AddExec(
"myexec",
"myexec()");
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TStyle * gStyle
2-D histogram with a float per channel (see TH1 documentation)
void SetPadGridX(Bool_t gridx)
void SetPadGridY(Bool_t gridy)
- Author
- Luigi Bardelli barde.nosp@m.lli@.nosp@m.fi.in.nosp@m.fn.i.nosp@m.t
Definition in file mandelbrot.C.