【发布时间】:2020-08-03 23:37:12
【问题描述】:
我最近发现了 Mandelbrot 集,现在我正在尝试在 Processing 3.0 中生成一个 Mandelbrot 集。我在youtube 上找到了一个关于编程的教程,并试图在 Progressing 中实现它。
background(255);
size(1280, 720);
}
void draw(){
int maxIteration = 100;
double reMid = -0.75;
double iMid = 0;
double rangeR = 3.5;
double rangeI = 2;
double xPixels = 1280;
double yPixels = 720;
for(int x = 0; x < xPixels; x++){
for(int y = 0; y < yPixels; y++){
double xP = (double)x / xPixels;
double yP = (double)y / yPixels;
double cReal = xP * rangeR + reMid - rangeR / 2;
double cIm = yP * rangeI + iMid - rangeI / 2;
double zReal = 0;
double zIm = 0;
int iteration = 0;
while(iteration < maxIteration && zReal * zReal + zIm * zIm <= 4) {
double temp = zReal * zReal - cIm * cIm + cReal;
zIm = 2 * zReal * zIm + cIm;
zReal = temp;
iteration++;
}
if(iteration >= maxIteration - 1){
stroke(0);
}
else{
stroke(255);
}
point(x, y);
}
}
}
但是当我生成 Mandelbrot 集时,它看起来与应有的不同:
我已经将我的代码与视频中的代码进行了比较,但我没有发现我的代码有错误。 有谁知道我做错了什么?
【问题讨论】:
标签: math processing fractals mandelbrot