我正在研究一个学校项目,用c ++生成一些逃逸时间分形。 Mandelbrot和Julia正常工作。 对于燃烧船舶分形,这是代码:
double x0, y0;//initial co-ordinates before iterations
x0=cx; y0=cy; //being passes on values from another fn, initially -2 and -2
for(int i= 30; i<=630; i++,x0+=(double)1/m, y0=cy)//m is for the magnification
{
for(int j= 630 ; j>=30; j--,y0+=(double)1/m)
{
double x= 0.0, y= 0.0, t;
int k= -1;
while(( x*x + y*y <4)&& k<it-1)
{
t= x*x - y*y + x0;
y= 2*abs(x*y) + y0;
x=t;
k++;
}
p= k*pd;
setcolor(COLOR(colour[p][0],colour[p][1],colour[p][2]));
putpixel(i,j,getcolor());
}
}
,与Mandelbrot集的代码相同,除了
y=2*x*y + y0;
对于Mandelbrot集,您使用
y=2*abs(x*y) + y0;
根据我读到的内容,对于燃烧船舶的分形,。 但输出完全不同。
有人可以指出代码中是否有任何错误或我可能需要知道的任何其他内容?
(这是生成图像的link,在从(-2,2)到(2,2)的矩形的每个点上进行100次迭代。)
这是不使用的代码,使用屏幕作为O / P.
double x0, y0, t;
x0=-2,y0=-2;
for(double cx=x0; cx<=2; cx=cx+0.1, cy=-2)//cx, cy: just loop counters.
{
for(double cy=y0; cy<=2; cy=cy+0.1)
{
double x= 0.0, y= 0.0;
int k= -1;
while(( x*x + y*y <4)&& k<9)//k- no. of times it takes to escape out
{
t= x*x - y*y + cx;
y= 2*abs(x*y) + cy;
x=t;
k++;
}
cout<<k; //for output
}
cout<<endl;
}
与前面的代码示例相同,除了总迭代(10)的固定值,精度(0.1)。 O / P是:
0000000000000000000000000000000000000000
0000000000000023999999999310000000000000
0000000000002229999999999911100000000000
0000000000222229999999999911111000000000
0000000022222299999999999991111100000000
0000000322222249999999999931111111000000
0000003352222249999999999932111111100000
0000023334222599999999999993111111110000
0000114835424499999999999993311111110000
0000112433444499999999999993331111111000
0001111473948699999999999995532111111100
0001111999596999999999999999592211111100
0011111299759999999999999999942211111110
0011111119959999999999999999842211111110
0111111119999999999999999999942211111111
0111111119999999999999999999942211111111
0111111119999999999999999999942211111111
0111111119999999999999999999992211111111
0111111149999999999999999999992211111111
0111111199999999999999999999992221111111
0111111199999999999999999999992221111111
0111111199999999999999999999999221111111
0111111999999999999999999999999222111111
0111111999999999999999999999999922111111
0111114999999999997666799999999922211111
0111114999999999654444456999999992211111
0112149999999995433333334599999994221111
0012229999999943333222333349999995211110
0022299999999432222222222234999991111110
0002299999993222222222222222399911111100
0002699999932222222212222222221111111100
0000899943222211111111111112221111111000
0000094222211111111111111111111111110000
0000022222111111111111111111111111110000
0000002211111111111111111111111111100000
0000000111111111111111111111111111000000
0000000001111111111111111111111100000000
0000000000111111111111111111111000000000
0000000000001111111111111111100000000000
0000000000000011111111111110000000000000