?? period.cpp
字號(hào):
// 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)
#define ABS(X) ((X)>0?(X):-(X))
struct PixelInfo
{
datetype a,b;
int lvl;
bool out;//計(jì)算完畢
};
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", "Mandebrot Peri", 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)
{
double perilimit=1e-2;
PixelInfo *info;
// datetype a, b, olda, oldb,;
CComplex z, oldz, z0;
int x, y, t;
int countxy;
datetype a1, b1, z2;
for (x = 0 ;x < wid; x++)
for (y = 0 ; y<hei;y++)
{
countxy=x+(hei-y-1)*wid;
info=pixelinfo+countxy;
if(!info->out)
{
z0.x=x*scale + left;
z0.y=y*scale + top;
if(info->lvl==0)
{
z=0; }
else
{
z.x=info->a;
z.y=info->b;
}
a1*=(a1=z.x);
b1*=(b1=z.y);
z2=a1+b1;
// olda=x*scale + left;
// oldb=y*scale + top;
oldz=z;
for (t = 0; t<lvl;t++)
{
//z=z*z+z0;
z.y=2*(z.x*z.y)+z0.y;
z.x=a1-b1+z0.x; a1*=(a1=z.x);
b1*=(b1=z.y);
z2=a1+b1;
if (z2 > 4)
{
info->out=true;
info->lvl+=t;
break;
}
if(t>20&&ABS(oldz.x-z.x)<perilimit&&ABS(oldz.y-z.y)<perilimit)
{
info->out=true;
info->lvl=-1;
break;
}
if(t%16==7)
{
oldz=z;
}
}
if(t==lvl)
{
info->a=z.x;
info->b=z.y;
info->lvl+=lvl;
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -