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

📄 mandelbrot.cpp

📁 自己写的一个分形程序
💻 CPP
字号:
// testdll.cpp : Defines the entry point for the DLL application.
//


int __stdcall DllMain( long hModule, int  ul_reason_for_call, void* lpReserved){return 1;}

// This is an example of an exported variable
//TESTDLL_API int nTestdll=0;
#define datetype double
#define Z(A, B) CComplex(A, B)

struct PixelInfo
{
	datetype a,b;
	int lvl;
	bool out;//计算完毕
};
struct FractalData
{
	char* expression, *origin, *name;
	bool tempor;
};

struct CComplex
{
	datetype x,y;
	CComplex() {};
	CComplex(datetype sx, datetype sy):x(sx),y(sy){};
	CComplex(const CComplex& cmp):x(cmp.x),y(cmp.y){};
	CComplex(double	d):x(d),y(0){};

	CComplex operator=(const CComplex& cmp) {x=cmp.x; y=cmp.y;return *this;};
	CComplex operator+=(const CComplex& cmp) {x+=cmp.x; y+=cmp.y;};
	CComplex operator-=(const CComplex& cmp) {x-=cmp.x; y-=cmp.y;};
	CComplex operator*=(const CComplex& cmp)
	{double temp=x; x=x*cmp.x-y*cmp.y; y=temp*cmp.y+cmp.x*y;};

	friend	CComplex operator+(datetype,CComplex& cmp);
	friend	CComplex operator-(datetype,CComplex& cmp);
	friend	CComplex operator*(datetype,CComplex& cmp);
	friend	CComplex operator/(datetype,CComplex& cmp);

	CComplex operator+(CComplex& cmp) const;
	CComplex operator-(CComplex& cmp) const;
	CComplex operator*(CComplex& cmp) const;
	CComplex operator/(CComplex& cmp) const;
	CComplex operator+(datetype dx) const;
	CComplex operator-(datetype dx) const;
	CComplex operator*(datetype dx) const;
	CComplex operator/(datetype dx) const;
	CComplex operator^(int n) const;
};

inline CComplex CComplex::operator+(CComplex& cmp2) const
	{ CComplex cmp(*this); cmp.x+=cmp2.x; cmp.y+=cmp2.y; return cmp; }

inline CComplex CComplex::operator-(CComplex& cmp2) const
	{ CComplex cmp(*this); cmp.x-=cmp2.x; cmp.y-=cmp2.y; return cmp; }

inline CComplex CComplex::operator*(CComplex& cmp2) const
	{ CComplex cmp(x*cmp2.x-y*cmp2.y, x*cmp2.y+cmp2.x*y); return cmp; }

inline CComplex CComplex::operator/(CComplex& cmp2) const
	{ datetype temp=cmp2.x*cmp2.x+cmp2.y*cmp2.y;
	if(temp<1e-14) return 0;
	CComplex cmp((x*cmp2.x+y*cmp2.y)/temp, (-x*cmp2.y+cmp2.x*y)/temp); return cmp; }

inline CComplex operator+(datetype dx,CComplex&cmp)
{ return CComplex(dx+cmp.x,cmp.y);}

inline CComplex operator-(datetype dx,CComplex&cmp)
{ return CComplex(dx-cmp.x,-cmp.y);}

inline CComplex operator*(datetype dx,CComplex&cmp)
{ return CComplex(dx*cmp.x,dx*cmp.y);}

inline CComplex operator/(datetype dx,CComplex&cmp)
{ datetype temp=cmp.x*cmp.x+cmp.y*cmp.y;
  return CComplex(dx*cmp.x/temp,-dx*cmp.y/temp); }

inline CComplex CComplex::operator+(datetype dx) const
	{ CComplex cmp(*this); cmp.x+=dx; return cmp; }

inline CComplex CComplex::operator-(datetype dx) const
	{ CComplex cmp(*this); cmp.x-=dx; return cmp; }

inline CComplex CComplex::operator*(datetype dx) const
	{ CComplex cmp(*this); cmp.x*=dx; cmp.y*=dx; return cmp; }

inline CComplex CComplex::operator/(datetype dx) const
	{ CComplex cmp(*this); cmp.x/=dx; cmp.y/=dx; return cmp; }

inline CComplex CComplex::operator^(int n) const
	{ CComplex cmp(*this); for(int i=0;i<n-1;i++) cmp*=(*this); return cmp; }

extern "C"{
FractalData fractaldata={"z*z+z0", "0", "Mandelbrot", true};__declspec(dllexport) const FractalData* GetFractalData() {return &fractaldata;}

__declspec(dllexport) void CalcFractal(PixelInfo *pixelinfo, double left, double top, double scale, int wid, int hei, int lvl)
{
	PixelInfo *info;
//	datetype a, b, olda, oldb,;
	CComplex z, oldz, z0;
	int x, y, t;
	int countxy;
	datetype z2, olda, oldb;
	datetype a1, b1, a, b;
	for (x = 0 ;x < wid; x++)
		for (y = 0 ; y<hei;y++)
		{
			countxy=x+(hei-y-1)*wid;
			info=pixelinfo+countxy;
			if(!info->out)
			{
				olda=x*scale + left;
				oldb=y*scale + top;
				a=0;b=0;				a1=0;
				b1=0;
//				olda=x*scale + left;
//				oldb=y*scale + top;
				for (t = 0; t<lvl;t++)
				{
					b=(a*b)*2+oldb; a=a1-b1+olda; a1=a*a; b1=b*b;
					if (a1+b1 > 4)
					{
						info->out=true;
						info->lvl=t;
						break;
					}
				}
			}
		}
}


}

⌨️ 快捷键说明

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