学数学的时候看到书上的函数绘图 于是用MFC和GDI+ 实现了一个简单绘图程序
MFC 还是那么难用
GDI+ 就是为了抗锯齿
另外绘图的时候x轴与y轴的比例是不一样 真实比例画出来的图是很不和谐的
https://download.csdn.net/download/geforceno1/11149948
void CmyMathView::OnDraw(CDC* pDC)
{
CmyMathDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
Graphics graphics(pDC->m_hDC);
Gdiplus::Pen pen(Color(255, 0, 0, 255), 1);
RECT rect;
GetClientRect(&rect);
int w = rect.right;
int h = rect.bottom;
int w2 = rect.right / 2;
int h2 = rect.bottom / 2;
graphics.SetSmoothingMode(SmoothingModeHighQuality);
CList
for (float x = -w2; x < w2; x+=0.1f)
{
float y = x;
switch (m_fType)
{
case 0: y = x; break;
case 1: y = pow(x, 2); break;
case 2: y = 1 + 1 / x; break;
case 3: y = 1 / x; break;
case 4: y = sin(x); break;
case 5: y = cos(x); break;
}
if (m_fType == 0)
srcPoints.AddTail(Gdiplus::Point(x + w2, (h2 - y)));
else if (m_fType == 2)
srcPoints.AddTail(Gdiplus::Point(x * 20 + w2, (h2 - y * 80)));
else
srcPoints.AddTail(Gdiplus::Point(x * 50 + w2, (h2 - y * 100)));
}
Gdiplus::Point * points = new Gdiplus::Point[srcPoints.GetCount()];
POSITION position = srcPoints.GetHeadPosition();
int index = 0;
while (position)
{
Gdiplus::Point & point = srcPoints.GetNext(position);
points[index].X = point.X;
points[index].Y = point.Y;
index++;
}
graphics.DrawCurve(&pen, points, srcPoints.GetCount());
delete[] points;
Gdiplus::Pen pen2(Color(255, 200, 200, 200), 1);
graphics.DrawLine(&pen2, Point(0, h2), Point(w, h2));
graphics.DrawLine(&pen2, Point(w2, 0), Point(w2, h));
}