00001 //macro illustrating how to animate a picture using a Timer 00002 //Author: Rene Brun 00003 00004 #include "TStyle.h" 00005 #include "TCanvas.h" 00006 #include "TF2.h" 00007 #include "TTimer.h" 00008 00009 Double_t pi; 00010 TF2 *f2; 00011 Float_t t = 0; 00012 Float_t phi = 30; 00013 void anim() 00014 { 00015 gStyle->SetCanvasPreferGL(true); 00016 gStyle->SetFrameFillColor(42); 00017 TCanvas *c1 = new TCanvas("c1"); 00018 c1->SetFillColor(17); 00019 pi = TMath::Pi(); 00020 f2 = new TF2("f2","sin(2*x)*sin(2*y)*[0]",0,pi,0,pi); 00021 f2->SetParameter(0,1); 00022 f2->SetNpx(15); 00023 f2->SetNpy(15); 00024 f2->SetMaximum(1); 00025 f2->SetMinimum(-1); 00026 f2->Draw("glsurf1"); 00027 TTimer *timer = new TTimer(20); 00028 timer->SetCommand("Animate()"); 00029 timer->TurnOn(); 00030 } 00031 void Animate() 00032 { 00033 //just in case the canvas has been deleted 00034 if (!gROOT->GetListOfCanvases()->FindObject("c1")) return; 00035 t += 0.05*pi; 00036 f2->SetParameter(0,TMath::Cos(t)); 00037 phi += 2; 00038 gPad->SetPhi(phi); 00039 gPad->Modified(); 00040 gPad->Update(); 00041 }