Image . Canvas (, ), , . , C++Builder.
X Y. , C++Builder, . X , Y − .
. − , . − . TColor. C++Builder TColor. (, clBlue − ), , Windows (, clBtnFace − ).
Pixels. Canvas->Pixels[int X][int Y], . , Canvas->Pixels[10][20] , 10- 20- . : , , . , Canvas->Pixels[10][20]=clBlack − .
, F(X) Image1, Ymax Ymin Xmin Xmax. :
float X,Y; //
int PX,PY; //
for(PX=0;PX<=Image1->Width;PX++)
{
// X - , PX
X=Xmin+PX*(Xmax-Xmin)/Image1->Width;
Y=F(X);
// PY - , Y
PY=Image1->Height-(Y-Ymin)* Image1->Height/(Ymax-Ymin);
//
Image1->Canvas->Pixels[PX][PY]=clRed;
}
PX Image1. PX X. Y. PY. (PX, PY) .
sin(X), Xmin =0, Xmax =4 (2 ), Ymin =-1 Ymax =1.
− Pen − . , . Color − , . − Width ( ). . 1.
|
|
Style :
psSolid | |
psDash | |
psDot | |
psDashDot | - |
psDashDotDot | , |
psClear | |
psInsideFrame | , Width>1 , Windows |
Width =1. .
psInsideFrame − , . Windows.
PenPos. . , .. PenPos, MoveTo(X,Y). (X,Y) − , . , LineTo(X,Y) (X,Y). , LineTo .
.
1. ( Windows), C++Builder 6, , IMAGE .
2. Image . , . , Size.
3. , Label1 , − Label2, .
4. Button1 . Close();.
5. Button2, , :
void __fastcall TForm1::Button2Click(TObject *Sender)
{
#define Pi 3.14159
float X,Y; //
int PX,PY; //
// -
//
Image2->Canvas->MoveTo(0,Image2->Height/2);
//
Image2->Canvas->Pen->Color=clRed;
//
Image2->Canvas->Pen->Width=3;
for(PX=0;PX<=Image1->Width;PX++)
{
// X - , PX
X=PX*4*Pi/Image1->Width;
Y=sin(X);
// PY - , Y
PY=Image1->Height-(Y+1)* Image1->Height/2;
//
Image1->Canvas->Pixels[PX][PY]=clRed;
//
Image2->Canvas->LineTo(PX,PY);
}
}
6. #include <math.h>. . , . − − . . , , .
|
|
Image − , . , Image, . , : Y=2*sin(X);. . , , . , - .
1. Chart.