void triangles(Int_t ntriangles=50) { //generate small triangles randomly in the canvas. //Each triangle has a unique id and a random color in the color palette //root > .x triangles.C //then click on any triangle. A message showing the triangle number //and its color will be printed. //Author: Rene Brun TCanvas *c1 = new TCanvas("c1","triangles",10,10,700,700); TRandom r; Double_t dx = 0.2; Double_t dy = 0.2; Int_t ncolors = gStyle->GetNumberOfColors(); Double_t x[4],y[4]; for (Int_t i=0;iSetUniqueID(i); pl->SetFillColor(ncolors*r.Rndm()); pl->Draw("f"); } c1->AddExec("ex","TriangleClicked()"); } void TriangleClicked() { //this action function is called whenever you move the mouse //it just prints the id of the picked triangle //you can add graphics actions instead int event = gPad->GetEvent(); if (event != 11) return; //may be comment this line TObject *select = gPad->GetSelected(); if (!select) return; if (select->InheritsFrom(TPolyLine::Class())) { TPolyLine *pl = (TPolyLine*)select; printf("You have clicked triangle %d, color=%d\n", pl->GetUniqueID(),pl->GetFillColor()); } }