?? magnet.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={"?", "0", "Magnet", 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 a1, b1, z2, zpr=0, zip=0, br, tmp;
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;
z=0; a1*=(a1=z.x);
b1*=(b1=z.y);
// z2=a1+b1;
// olda=x*scale + left;
// oldb=y*scale + top;
for (t = 0; t<lvl;t++)
{
br = z.x + z.x + z0.x - 2;
tmp = z.x * z.y;
z.x = a1 - b1 + z0.x - 1;
b1 = z.y + z.y + z0.y;
z.y = tmp + tmp + z0.y;
tmp = 1 / (br * br + b1 * b1);
a1 = (z.x * br + z.y * b1) * tmp;
b1 = (z.y * br - z.x * b1) * tmp;
z.x = (a1 + b1) * (a1 - b1);
z.y = a1 * b1;
z.y += z.y;
a1 = z.x - 1;
b1 = z.y * z.y;
a1 = z.x * z.x;
// a1*=(a1=z.x);
// b1*=(b1=z.y);
// z2=a1+b1;
if ((a1-2*z.x+b1)+1<0.01)
{
info->out=true;
info->lvl+=t;
break;
}
}
if(t==lvl)
{
info->a=z.x;
info->b=z.y;
info->lvl+=lvl;
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -