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[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",
}
}
- Author
- Rene Brun
Definition in file triangles.C.