?? phoenix.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={"?", "z0", "Phoenix", 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 rp, ip, a, b, pre, pim, zpr, zip, zre, zim;
for (x = 0 ;x < wid; x++)
for (y = 0 ; y<hei;y++)
{
countxy=x+(hei-y-1)*wid;
info=pixelinfo+countxy;
if(!info->out)
{
pre=x*scale + left;
pim=y*scale + top;
zpr=zip=0;
zre=pre;
zim=pim;
rp = zre * zre;
ip = zim * zim;
// olda=x*scale + left;
// oldb=y*scale + top;
for (t = 0; t<lvl;t++)
{
rp = rp - ip + pre + pim * zpr;
ip = 2 * zre * zim + pim * zip;
zpr = zre, zip = zim; zre = rp;
zim = ip; rp = zre * zre, ip = zim * zim;
if (rp+ip > 4)
{
info->out=true;
info->lvl=t;
break;
}
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -