Canvas对象的Polyline函数可以用来非常简单地显示一些曲线.本例子分别用sin,cos和ramdom函数填充TPoint对象,然后
调用Canvas->Polyline,在窗体上显示相应的曲线.代码和显示效果图如下:
void __fastcall TForm1::Button3Click(TObject *Sender)
{
TPoint sinp[360+1];
TPoint cosp[360+1];
TPoint ranp[360+1];
int i;
Randomize;//初始化随机数种子
for (i=0; i<360; i++) {
sinp.x=20+i;
sinp.y=100+100*Sin(3.1415926*i/180);//SIN曲线
cosp.x=20+i;
cosp.y=100+100*Cos(3.1415926*i/180);//COS曲线
ranp.x=20+i;
ranp.y=Random(255);//用随机数填充
}
sinp[360]=sinp[359];
cosp[360]=cosp[359];
ranp[360]=ranp[359];
this->Canvas->Pen->Color = clRed;//用红色画笔绘制SIN曲线
this->Canvas->Polyline(sinp,360);
this->Canvas->Pen->Color = clGreen;//用绿色画笔绘制COS曲线
this->Canvas->Polyline(cosp,360);
this->Canvas->Pen->Color = clGray;//用灰色画笔绘制随机数曲线
this->Canvas->Polyline(ranp,360);
}
Canvas对象的其它绘制函数如下图所示.
<梅川酷子原创>
文章评论(0条评论)
登录后参与讨论