//_______________________________________________________________ // // This macro creates a 3D spiral using TPolyMarker3D. // In the loop it takes snapshots of the growing picture. // With the help of the program "gifsicle" it assembles // the snapshot into a movie which may be viewed by // "gifview" or by a browser like mozilla. // Information on "gifsicle" can be found here: // http://www.lcdf.org/~eddietwo/gifsicle/ // // Author: Otto Schaile //________________________________________________________________ { gROOT->Reset(); gStyle->SetTitleSize(0.03, "x"); gStyle->SetTitleOffset(1.5, "x"); gStyle->SetTitleSize(0.03, "y"); gStyle->SetTitleOffset(1.5, "y"); gStyle->SetTitleSize(0.03, "z"); gStyle->SetTitleOffset(1.5, "z"); gStyle->SetTitleColor(kBlue, "x"); gStyle->SetTitleColor(kBlue, "y"); gStyle->SetTitleColor(kBlue, "z"); Int_t ppc=30; Int_t ncircles = 5; // create and open a canvas TCanvas * cc = new TCanvas( "cc", "Spiral", 300, 10, 700, 700 ); cc->SetFillColor(1); // create view with axis Double_t rx0 = 0, rx1 = 5, ry0 = 0, ry1 = 5, rz0 = 0, rz1 = 5; Double_t rmin[3], rmax[3]; rmin[0] = rx0; rmin[1] = ry0; rmin[2] = rz0; rmax[0] = rx1; rmax[1] = ry1; rmax[2] = rz1; TView3D *view = new TView3D(1, rmin, rmax); view->ShowAxis(); TAxis3D *axis = TAxis3D::GetPadAxis(); // Get pointer to axis if (axis) { axis->SetLabelSize(0.02); axis->SetLabelOffset(-0.02, "z"); axis->SetLabelColor(kBlue); axis->SetAxisColor(kBlue); axis->SetXTitle("East"); axis->SetYTitle("North"); axis->SetZTitle("Altitude"); } // draw a box around TPolyLine3D *pl3d; pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx0, ry1, rz0); pl3d->SetPoint(1,rx1, ry1, rz0); pl3d->SetLineColor(kBlue); pl3d->Draw(); pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx0, ry1, rz1); pl3d->SetPoint(1,rx1, ry1, rz1); pl3d->SetLineColor(kBlue); pl3d->Draw(); pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx1, ry0, rz0); pl3d->SetPoint(1,rx1, ry1, rz0); pl3d->SetLineColor(kBlue); pl3d->Draw(); pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx1, ry0, rz1); pl3d->SetPoint(1,rx1, ry1, rz1); pl3d->SetLineColor(kBlue); pl3d->Draw(); pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx1, ry0, rz0); pl3d->SetPoint(1,rx1, ry0, rz1); pl3d->SetLineColor(kBlue); pl3d->Draw(); pl3d = new TPolyLine3D(2); pl3d->SetPoint(0,rx1, ry1, rz0); pl3d->SetPoint(1,rx1, ry1, rz1); pl3d->SetLineColor(kBlue); pl3d->Draw(); // draw a grid on x-y plane z = 0 Double_t gr = rx0 + 1; while (gr < rx1) { pl3d = new TPolyLine3D(2); pl3d->SetPoint(0, gr, ry0, rz0); pl3d->SetPoint(1, gr, ry1, rz0); pl3d->SetLineColor(kBlue); pl3d->Draw(); gr += 1; } gr = ry0 + 1; while (gr < ry1) { pl3d = new TPolyLine3D(2); pl3d->SetPoint(0, rx0, gr, rz0); pl3d->SetPoint(1, rx1, gr, rz0); pl3d->SetLineColor(kBlue); pl3d->Draw(); gr += 1; } // create a PolyMarker3D TPolyMarker3D *pm3d; Double_t dphi = 2. * TMath::Pi() / ppc; Double_t dr = 0.01; Double_t dx = 0.015; Double_t dz = 0.0004; Double_t phi = 0; Double_t x0 = 0.1 * (rx1 - rx0); Double_t y0 = 0.5 * (ry1 - ry0); Double_t r = dr; Double_t z = rz0; Double_t x, y; TString pname; TList * mlist = new TList(); Int_t n = 0; // for( Int_t i = 0; i < ppc * ncircles; i++ ) { // for( Int_t i = 0; i < 1; i++ ) { while (z <= rz1) { pm3d = new TPolyMarker3D(1); mlist->AddFirst(pm3d); pm3d->SetPoint( 0, x0, y0, z ); pm3d->SetMarkerSize(0.5); pm3d->SetMarkerStyle( 3 ); pm3d->SetMarkerColor( 6 ); pm3d->Draw(); pm3d = new TPolyMarker3D(1); mlist->AddFirst(pm3d); x = x0 + r * TMath::Cos(phi); y = y0 + r * TMath::Sin(phi); pm3d->SetPoint( 0, x, y, z ); pm3d->SetMarkerSize(0.5); pm3d->SetMarkerStyle( 8 ); pm3d->SetMarkerColor( 2 + 3 * (n%2) ); pm3d->Draw(); if ( !(n%4) ) { // take snapshot every 2nd picture only cc->Modified(); cc->Update(); pname = "spiral_"; pname += Form("%03d", n); pname += ".gif"; cc->SaveAs(pname.Data()); } // gSystem->Sleep(20); x0 += dx; z += dz * n; r += dr; phi += dphi; n++; } TIter next(mlist); while (pm3d = (TPolyMarker3D*)next()){ delete pm3d; if ( !(n%4) ) { // take snapshot every 2nd picture only cc->Modified(); cc->Update(); pname = "spiral_"; pname += Form("%03d", n); pname += ".gif"; cc->SaveAs(pname.Data()); } n++; } // assemble the movie gSystem->Exec("gifsicle -O2 --delay=5 --loop=5 spiral_*.gif > spanim.gif"); gSystem->Exec("rm -f spiral_*.gif"); gSystem->Exec("gifview -a spanim.gif"); }