C++画曲线源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

// ÇúÏßView.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "ÇúÏß.h"
#include "ÇúÏßDoc.h"
#include "ÇúÏßView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////// ///////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_WM_LBUTTONDOWN()
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////// ///////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
t1=5,t2=5;
nPoints=0;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
////////////////////////////////////////////////////////////////// ///////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int j;
if (nPoints!=4) return;
else nPoints%=4;
for (j=0;j<3;j++)
{
pDC->MoveTo(pp[j]);
pDC->LineTo(pp[(j+1)%4]);
}
CPoint p0,p1,pt;
float t,h0,h1,h2,h3,pdox,pdoy,pdlx,pdly;
p0=pp[1];
p1=pp[2];
pdox=t1*(pp[1].x-pp[0].x);
pdoy=t1*(pp[1].y-pp[0].y);
pdlx=t2*(pp[2].x-pp[3].x);
pdly=t2*(pp[2].x-pp[3].y);
for(t=0;t<=1;t+=0.001)
{
h0=2*t*t*t-3*t*t+1;
h1=-2*t*t*t+3*t*t;
h2=t*t*t-2*t*t+t;
h3=t*t*t-t*t;
pt.x=p0.x*h0+p1.x*h1+pdox*h2+pdlx*h3;
pt.y=p0.y*h0+p1.y*h1+pdoy*h2+pdly*h3;
pDC->SetPixel(pt,RGB(255,0,0));
}
// TODO: add draw code for native data here
}
////////////////////////////////////////////////////////////////// ///////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) {
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) {
// TODO: add cleanup after printing
}
////////////////////////////////////////////////////////////////// ///////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
////////////////////////////////////////////////////////////////// ///////////
// CMyView message handlers
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default pp[nPoints++]=point;
CView::OnLButtonDown(nFlags, point);
if(nPoints==4)
Invalidate(FALSE);
}
void CMyView::OnCancelMode()
{
CView::OnCancelMode();
// TODO: Add your message handler code here
}。

相关文档
最新文档