资 源 简 介
VC++ 6.0 绘制曲线正弦波,一种比较有规律的曲线,源代码也是相当简单的好种。
//建立画笔
CPen cpen,pen;
pen.CreatePen(PS_SOLID,4,RGB(0,0,0));
cpen.CreatePen(PS_SOLID,2,RGB(0,0,255));
pDC->SelectObject(&cpen);
//指定原点
pDC->SetViewportOrg(100,245);
pDC->SetTextColor(RGB(255,0,0));
//绘制横坐标
CString sPIText[]={"-1/2π","","1/2π","π","3/2π","2π","5/2π","3π","7/2π","4π","9/2π","5π"};
for(int n=-1,nTmp=0;nTmp<=660;n++,nTmp+=60)
{
pDC->LineTo(60*n,0);
pDC->LineTo(60*n,-5);
pDC->MoveTo(60*n,0);
pDC->TextOut(60*n-sPIText[n+1].GetLength()*3,16,sPIText[n+1]);
}
double y,radian;
pDC->SelectObject(&pen);
for(int x=-60;x<600;x++)
{
//弧度=X坐标/曲线宽度*角系数*π
//Y坐标=振幅*曲线宽度*sin(弧度)
radian =x/((double)60*2)*PI;
y=sin(radian)*2*60;
pDC->MoveTo((int)x,(int)y);
pDC->LineTo((int)x,(int)y);
}