fractview.cpp
来自「用vc++实现的一个算法程序」· C++ 代码 · 共 174 行
CPP
174 行
// FractView.cpp : implementation of the CFractView class
//
#include "stdafx.h"
#include "Fract.h"
#include "FractDoc.h"
#include "FractView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFractView
IMPLEMENT_DYNCREATE(CFractView, CView)
BEGIN_MESSAGE_MAP(CFractView, CView)
//{{AFX_MSG_MAP(CFractView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CFractView construction/destruction
CFractView::CFractView()
{
// TODO: add construction code here
xmin0=100.0;
xmax0=-100.0;
ymin0=100.0;
ymax0=-100.0;
a=0.7;
b=0.3;
c=0.5;
d=0.3;
x0=1.0;
count=0;
recdepth=15;
}
CFractView::~CFractView()
{
}
BOOL CFractView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFractView drawing
void CFractView::OnDraw(CDC* pDC)
{
CFractDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int i;
level_5 = recdepth-5;
transf( 1, 0, recdepth, 1, pDC );
fx = 10.0/(xmax0-xmin0);
fy = 7.0/(ymax0-ymin0);
f = (fx<fy ? fx : fy)*0.8;
xc0 = (xmin0+xmax0)/2;
yc0 = (ymin0+ymax0)/2;
xc = 5.0; yc = 3.5;
count=0;
transf( 1.0, 0.0, recdepth, 0, pDC );
for(i=1; i<=32; i++)
pDC->SetPixel( 8*i, 0, 1);
}
void CFractView::transf( double x, double y, int n, int prescan, CDC *pDC )
{
double x1, y1;
if( n > 0 )
{
if( prescan )
{
if( n==level_5 ) printf("%d ", ++count);
if( x<xmin0 ) xmin0=x;
if( x>xmax0 ) xmax0=x;
if( y<ymin0 ) ymin0=y;
if( y>ymax0 ) ymax0=y;
}
else
{
if( n==level_5 )
pDC->SetPixel( count+=8, 0, 7);
pDC->SetPixel( xint(x), yint(y), RGB(0, 255, 0) );
}
x1 = a*x+b*y;
y1 = b*x-a*y;
transf( x1, y1, n-1, prescan, pDC );
x1 = c*(x-x0) - d*y + x0;
y1 = d*(x-x0) + c*y;
transf( x1, y1, n-1, prescan, pDC );
}
}
int CFractView::xint( double x )
{
return (int)((xc+f*(x-xc0))*64+0.5);
}
int CFractView::yint( double y )
{
return (int)(480-(yc+f*(y-yc0))*48);
}
/////////////////////////////////////////////////////////////////////////////
// CFractView printing
BOOL CFractView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFractView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFractView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CFractView diagnostics
#ifdef _DEBUG
void CFractView::AssertValid() const
{
CView::AssertValid();
}
void CFractView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFractDoc* CFractView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFractDoc)));
return (CFractDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFractView message handlers
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?