⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mandlbrotview.cpp

📁 《分形算法与程序设计VC版》一书<5_02>:内含基于逃逸时间算法的Julia集源代码。双击Debug下的Julia.exe文件
💻 CPP
字号:
// MandlbrotView.cpp : implementation of the CMandlbrotView class
//

#include "stdafx.h"
#include "Mandlbrot.h"

#include "MandlbrotDoc.h"
#include "MandlbrotView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMandlbrotView

IMPLEMENT_DYNCREATE(CMandlbrotView, CView)

BEGIN_MESSAGE_MAP(CMandlbrotView, CView)
	//{{AFX_MSG_MAP(CMandlbrotView)
		// 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
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMandlbrotView construction/destruction

CMandlbrotView::CMandlbrotView()
{
	// TODO: add construction code here

	
	K=100;
	m=500;
	Mx=800;
	My=600;
	xs = -1.5; xl = 1.5; ys = -1.5; yl = 1.5;
	p = 0.32; q = 0.043;
}

CMandlbrotView::~CMandlbrotView()
{
}

BOOL CMandlbrotView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMandlbrotView drawing

void CMandlbrotView::OnDraw(CDC* pDC)
{
	CMandlbrotDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
    AfxGetMainWnd()->SetWindowText("Julia集(分形频道:fractal.cn)2004");
	xb = (xl - xs) / Mx;
    yb = (yl - ys) / My;
	for(nx=0;nx<=Mx;nx++)
         {
          for(ny=0;ny<=My;ny++)
			  
          {  x0=xs+nx*xb;
             y0=ys+ny*yb;
             k=0;
         loop1:
             xk=x0*x0-y0*y0+p;
             yk=2*x0*y0+q;
             k=k+1;
             r=xk*xk+yk*yk;
             x0=xk,y0=yk;
             if(r>m){
             H=k;
			 goto loop2;}
			 if(k==K){
             H=int(r*10);goto loop2;}
             if(r<=m && k<K) goto loop1;
         loop2:
             pDC->SetPixel(nx,ny,H*1000);
		  }		 
         		   
      }
}

/////////////////////////////////////////////////////////////////////////////
// CMandlbrotView diagnostics

#ifdef _DEBUG
void CMandlbrotView::AssertValid() const
{
	CView::AssertValid();
}

void CMandlbrotView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMandlbrotDoc* CMandlbrotView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMandlbrotDoc)));
	return (CMandlbrotDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMandlbrotView message handlers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -