-7
我写了一个应该绘制Mandelbrot分形的程序。不幸的是,它似乎醉了。下面是输出:醉Mandelbrot实现
相关功能:
void drawMandelbrot(float x, float y, float width, float height, float delta) {
for (float currentX = -2; currentX < 2; currentX += delta) {
for (float currentY = -2; currentY < 2; currentY += delta) {
Complex z(0, 0);
Complex c(currentX, currentY);
int iterations = 0;
do {
z = z * z + c;
++iterations;
}
while (z.getAbsoluteValue() <= 2 && iterations < MANDELBROT_ITERATION_LIMIT);
ALLEGRO_COLOR pixelColor;
float pixelX = (currentX + 2)/4 * width;
float pixelY = (currentY + 2)/4 * width;
if (z.getAbsoluteValue() <= 2) {
pixelColor = blackColor;
// Commented because you might not want this much junk in your terminal
//std::cout << "Stayed small! " << z.toString() << std::endl;
} else {
pixelColor = al_color_hsv(iterations/MANDELBROT_ITERATION_LIMIT, 1.0f, 1.0f);
// idem
//std::cout << "Blew up! " << z.toString() << std::endl;
}
al_draw_pixel(pixelX, pixelY, pixelColor);
}
}
}
我相信Complex::operator...
方法是正确的,我在上面的功能怀疑一个逻辑错误。当检查上面(注释过的)std :: cout语句的输出时,输出中复数的绝对值确实小于2,但图像看起来不像绘制的mandelbrot集。
错在何处?
编辑历史中包含mcve。
问题是什么? – Arkapravo
我们应该做什么?编译,执行和调试你的代码? –
@Arkapravo'drawMandelbrot()'中必须存在一些逻辑错误。我在网上看到的Mandelbrot系列的所有图片看起来都更对称。将编辑。 – 11684