00001 void triangles(Int_t ntriangles=50) {
00002
00003
00004
00005
00006
00007
00008
00009 TCanvas *c1 = new TCanvas("c1","triangles",10,10,700,700);
00010 TRandom r;
00011 Double_t dx = 0.2; Double_t dy = 0.2;
00012 Int_t ncolors = gStyle->GetNumberOfColors();
00013 Double_t x[4],y[4];
00014 for (Int_t i=0;i<ntriangles;i++) {
00015 x[0] = r.Uniform(.05,.95); y[0] = r.Uniform(.05,.95);
00016 x[1] = x[0] + dx*r.Rndm(); y[1] = y[0] + dy*r.Rndm();
00017 x[2] = x[1] - dx*r.Rndm(); y[2] = y[1] - dy*r.Rndm();
00018 x[3] = x[0]; y[3] = y[0];
00019 TPolyLine *pl = new TPolyLine(4,x,y);
00020 pl->SetUniqueID(i);
00021 pl->SetFillColor(ncolors*r.Rndm());
00022 pl->Draw("f");
00023 }
00024 c1->AddExec("ex","TriangleClicked()");
00025 }
00026
00027 void TriangleClicked() {
00028
00029
00030
00031 int event = gPad->GetEvent();
00032 if (event != 11) return;
00033 TObject *select = gPad->GetSelected();
00034 if (!select) return;
00035 if (select->InheritsFrom(TPolyLine::Class())) {
00036 TPolyLine *pl = (TPolyLine*)select;
00037 printf("You have clicked triangle %d, color=%d\n",
00038 pl->GetUniqueID(),pl->GetFillColor());
00039 }
00040 }