Generate small triangles randomly in the canvas.
Each triangle has a unique id and a random color in the color palette
Then click on any triangle. A message showing the triangle number and its color will be printed.
void triangles(
Int_t ntriangles=50) {
for (
Int_t 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();
x[3] =
x[0];
y[3] =
y[0];
}
c1->AddExec(
"ex",
"TriangleClicked()");
}
void TriangleClicked() {
int event =
gPad->GetEvent();
if (event != 11) return;
if (!select) return;
printf("You have clicked triangle %d, color=%d\n",
}
}
R__EXTERN TStyle * gStyle
virtual Color_t GetFillColor() const
Return the fill area color.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
The color creation and management class.
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
Mother of all ROOT objects.
virtual UInt_t GetUniqueID() const
Return the unique object id.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Defined by an array on N points in a 2-D space.
virtual void Draw(Option_t *option="")
Draw this polyline with its current attributes.
This is the base class for the ROOT Random number generators.
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
- Author
- Rene Brun
Definition in file triangles.C.