、在一个图形窗体中画出函数y=e
x和y=log
x,其中y=e
x取值
(-2;0.1;2),y=log
x取值(0.1;0.1;5),要求:要有图
例,标题(’二维图’),坐标轴标签(’x轴数据’和’y轴数据’),
背景为白色,函数曲线有注释。
下载一个SimpleCG库https://blog.csdn.net/b2b160/article/details/130435582?spm=1001.2014.3001.5502
代码如下
#include "../import/include/CGBoard.h"
#include "math.h"
#pragma comment(lib,"../import/lib/SimpleCG.lib")
int nWindowWidth = 800;
int nWindowHeight = 800;
float fRatioX = 0.01f;
float fRatioY = 0.01f;
typedef float (*FUNCTION)(float fX);
void DrawFunctionLine( FUNCTION pFun )
{
int x=0;
float fFx = 0.0f;
float fFLast = 0.0f;
int nLastX = 0;
int nXCenter=nWindowWidth/2;
int nYCenter=nWindowHeight/2;
fFLast = pFun(0-nXCenter)*fRatioX;
for( x=0; x<nWindowWidth; x++)
{
fFx = pFun(((float)x-nXCenter)*fRatioX);
fFx = (-fFx/fRatioY+nYCenter);
line(nLastX,fFLast,x,fFx);
fFLast=fFx;
nLastX=x;
}
}
void DrawProcess()
{
int y=0;
int x=0;
int nXCenter=nWindowWidth/2;
int nYCenter=nWindowHeight/2;
setline(PS_SOLID, 1, RGB(0,0,0));
line(0,nYCenter,nWindowWidth,nYCenter);
line(nXCenter,0,nXCenter,nWindowHeight);
for( y=0; y<nWindowHeight; y+=10)
{
line(nXCenter,y,nXCenter+3,y);
}
for( x=0; x<nWindowWidth; x+=10)
{
line(x,nYCenter,x,nYCenter+3);
}
DrawFunctionLine(exp);
DrawFunctionLine(log);
}
int _tmain(int argc, _TCHAR* argv[])
{
if( !ShowingBoard(nWindowWidth, nWindowHeight, DrawProcess))
return 1;
CloseBoard();
return 0;
}
图像