Create small triangles at random positions on the canvas.
Assign a unique ID to each triangle, and give each one a random color from the color palette.
When a triangle is clicked, a message displaying its unique number and color will be printed.
HpÿM*
void triangles(int ntriangles = 50)
{
auto c1 =
new TCanvas(
"c1",
"triangles", 10, 10, 700, 700);
double dx = 0.2;
double dy = 0.2;
for (int i = 0; i < ntriangles; i++) {
x[0] =
r.Uniform(.05, .95);
y[0] =
r.Uniform(.05, .95);
x[1] =
x[0] + dx *
r.Rndm();
y[1] =
y[0] + dy *
r.Rndm();
x[2] =
x[1] - dx *
r.Rndm();
y[2] =
y[1] - dy *
r.Rndm();
pl->SetUniqueID(i);
int ci = ncolors *
r.Rndm();
pl->SetFillColor(
c->GetNumber());
pl->Draw("f");
}
c1->AddExec(
"ex",
"TriangleClicked()");
}
void TriangleClicked()
{
int event =
gPad->GetEvent();
if (event != 11)
return;
if (!select)
return;
}
}
virtual Color_t GetFillColor() const
Return the fill area color.
static Int_t GetNumberOfColors()
static Int_t GetColorPalette(Int_t i)
Mother of all ROOT objects.
virtual UInt_t GetUniqueID() const
Return the unique object id.
This is the base class for the ROOT Random number generators.
- Author
- Rene Brun
Definition in file triangles.C.