Re: Simple drawing HOWTO needed

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sun Jun 29 1997 - 12:00:39 MEST


Terrence Brannon wrote:
> 
> I tried to paint a canvas grey and then fill each pixel with another
> color of pixel. But failed. How does one do this? I think this great
> material for the HOWTO section.
> 
> {
> r = new TCanvas("name", "title", 100, 100) ;
> r.SetFillColor(14);
> 
> TPolyMarker * pm2d = new TPolyMarker(100*100);
> 
> int count = 0;
> for (int i = 0; i < 100; ++i) {
>   for (int j = 0; j < 100; ++j) {
> 
>     printf ("%d,%d \n", i,j);
> 
>     pm2d->SetPoint(count++,j,i);
>     pm2d->Draw();
>   }
> }
> 
> r.Update();
> }

You forgot to set the range for the canvas (or may be confused
the canvas size in pixel units (100,100) with the canvas range
in user coordinates. By default the canvas range is set to [0,1].
In your example above, you should not call pm2d->Draw() for each point,
but only once.
I have modified your macro in the following way:

{
gROOT->Reset();
r = new TCanvas("name", "title", 600, 400) ;
r.SetFillColor(14);
r.Range(-20,-20,120,120);

TPolyMarker * pm2d = new TPolyMarker(100*100);
pm2d->SetMarkerColor(2);

int count = 0;
for (int i = 0; i < 100; ++i) {
  for (int j = 0; j < 100; ++j) {
    pm2d->SetPoint(count++,j,i);
  }
}
pm2d->Draw();

r.Update();
}


Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET