fillpatterns.C

Go to the documentation of this file.
00001 TCanvas * fillpatterns()
00002 {
00003    // Fill patterns example. This macro shows the available fill patterns.
00004    // The first table displays the 25 fixed patterns. They cannot be
00005    // customized unlike the hatches displayed in the second table which be 
00006    // cutomized using:
00007    //   - gStyle->SetHatchesSpacing() to define the spacing between hatches.
00008    //   - gStyle->SetHatchesLineWidth() to define the hatches line width.
00009    //
00010    // Author: Olivier Couet.
00011       
00012    TCanvas *Pat = new TCanvas("Fill Patterns", "",0,0,500,700);
00013    Pat->Range(0,0,1,1);
00014    Pat->SetBorderSize(2);
00015    Pat->SetFrameFillColor(0);
00016    Double_t bh = 0.059;
00017    Double_t db = 0.01; 
00018    Double_t y  = 0.995;
00019    Int_t i,j=3001;
00020 
00021    // Fixed patterns.
00022    for (i=1; i<=5; i++) {
00023       box(j++, 0.01, y-bh, 0.19, y);
00024       box(j++, 0.21, y-bh, 0.39, y);
00025       box(j++, 0.41, y-bh, 0.59, y);
00026       box(j++, 0.61, y-bh, 0.79, y);
00027       box(j++, 0.81, y-bh, 0.99, y);
00028       y = y-bh-db;
00029    }
00030 
00031    // Hatches
00032    y = y-3*db;
00033    gStyle->SetHatchesSpacing(2.0);
00034    gStyle->SetHatchesLineWidth(1);
00035    Int_t j1 = 3144;
00036    Int_t j2 = 3305;
00037    Int_t j3 = 3350;
00038    Int_t j4 = 3490;
00039    Int_t j5 = 3609;
00040    for (i=1; i<=9; i++) {
00041       if (i==6) {j2 += 10; j3 += 1; j4 += 1; j5 += 10;}
00042       if (i==5) {j4 -= 10; j5 -= 1;}
00043       box(j1, 0.01, y-bh, 0.19, y);
00044       box(j2, 0.21, y-bh, 0.39, y);
00045       box(j3, 0.41, y-bh, 0.59, y);
00046       box(j4, 0.61, y-bh, 0.79, y);
00047       box(j5, 0.81, y-bh, 0.99, y);
00048       j1 += 100;
00049       j2 += 10;
00050       j3 += 1;
00051       j4 -= 9;
00052       j5 += 9;
00053       y = y-bh-db;
00054    }
00055    return Pat;
00056 }
00057 
00058 box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t  y2)
00059 {
00060    // Draw an box using the fill pattern "pat" with the "pat" value
00061    // written on top.
00062 
00063    TBox b;
00064    b.SetFillColor(1);
00065    b.SetFillStyle(pat); b.DrawBox(x1,y1,x2,y2);
00066    b.SetFillStyle(0)  ; b.DrawBox(x1,y1,x2,y2);
00067    b.SetFillColor(0)  ; b.SetFillStyle(1000)  ;
00068    Double_t dx = (x2-x1)/3;
00069    Double_t dy = (y2-y1)/3;
00070    Double_t h  = (y2-y1)/2.5;
00071    b.DrawBox(x1+dx, y1+dy, x2-dx, y2-dy);
00072    b.SetFillStyle(0);
00073    b.DrawBox(x1+dx, y1+dy, x2-dx, y2-dy);
00074 
00075    TLatex l;
00076    l.SetTextAlign(22); l.SetTextSize(h);
00077    l.DrawLatex((x1+x2)/2, (y1+y2)/2, Form("%d",pat));
00078 }

Generated on Tue Jul 5 14:10:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1