niedziela, 9 stycznia 2022

Simple chart (C++ Builder)

 



void __fastcall TForm1::Button1Click(TObject *Sender)

{

 int pwidth,pheight,centrx,centry,rvalue,svalue,i,j;

 pwidth=PaintBox1->Width;

 pheight=PaintBox1->Height;

 centrx=pwidth/2;

 centry=pheight/2;

 rvalue=15;

 svalue=10;

 PaintBox1->Canvas->Brush->Color=clYellow;

 PaintBox1->Canvas->FillRect(PaintBox1->Canvas->ClipRect) ;

 PaintBox1->Canvas->Pen->Color=clBlack;

 PaintBox1->Canvas->MoveTo(centrx,0);

 PaintBox1->Canvas->LineTo(centrx,pheight);

 PaintBox1->Canvas->MoveTo(0,centry);

 PaintBox1->Canvas->LineTo(pwidth,centry);

 PaintBox1->Canvas->Pen->Color=clBlue;

 for(i=centrx+rvalue;i<pwidth+rvalue;i+=rvalue)

 {

  PaintBox1->Canvas->MoveTo(i,centry-svalue);

  PaintBox1->Canvas->LineTo(i,centry+svalue);

 }

 j=1;

 for(i=centry-rvalue;i>0;i-=rvalue)

 {

  PaintBox1->Canvas->MoveTo(centrx-svalue,i);

  PaintBox1->Canvas->LineTo(centrx+svalue,i);

  PaintBox1->Canvas->TextOut(centrx+(2*svalue),i-(svalue-1),IntToStr(j));

  ++j;

 }

 PaintBox1->Canvas->Pen->Color=clRed;

 for(i=centrx-rvalue;i>0;i-=rvalue)

 {

  PaintBox1->Canvas->MoveTo(i,centry-svalue);

  PaintBox1->Canvas->LineTo(i,centry+svalue);

 }

 j=1;

 for(i=centry+rvalue;i<pheight+rvalue;i+=rvalue)

 {

  PaintBox1->Canvas->MoveTo(centrx-svalue,i);

  PaintBox1->Canvas->LineTo(centrx+svalue,i);

  PaintBox1->Canvas->TextOut(i-(svalue-5),centry-(2*svalue),IntToStr(j));

  ++j;

 }

 PaintBox1->Canvas->Pen->Color=clGreen;

 PaintBox1->Canvas->MoveTo(centrx,0);

 PaintBox1->Canvas->LineTo(centrx-svalue,rvalue*2);

 PaintBox1->Canvas->MoveTo(centrx,0);

 PaintBox1->Canvas->LineTo(centrx+svalue,rvalue*2);

 PaintBox1->Canvas->MoveTo(pwidth,centry);

 PaintBox1->Canvas->LineTo(pwidth-(rvalue*2),centry-svalue);

 PaintBox1->Canvas->MoveTo(pwidth,centry);

 PaintBox1->Canvas->LineTo(pwidth-(rvalue*2),centry+svalue);


 PaintBox1->Canvas->TextOut(centrx-(3*rvalue),centry+rvalue,"(0,0)");


 PaintBox1->Canvas->Pen->Color=clGreen;

 PaintBox1->Canvas->MoveTo(centrx,centry);

 PaintBox1->Canvas->LineTo(pwidth,0);

 PaintBox1->Canvas->TextOut(centrx+(centrx/2)+rvalue,centry-(centry/2),"y=x");



}

Brak komentarzy:

Prześlij komentarz