c - 如何在 mandelbrot ppm 图像中获得更多细节
问题描述
当我在 C 中生成一个旨在表示 Mandelbrot 分形的 PPM 时,我只得到 4 个带有颜色的像素,表明它们属于该集合。这是有道理的,但是当我放大它并让我的 800X800 图像,每个像素代表一个介于 -2->2 之间的数字时,我在分形中没有得到额外的细节,它只是第一张图像中的“4”像素,但是每个都有 200x200 的大小。
我尝试过: - 在我的第二个函数中使用常量代替 (a/4) 和 (b/4)。- 改变图像的尺寸。- 在我的 FOR 循环中使用常量。- 评估 main() 函数中的每个像素,而不是单独的函数。- 在测试是否包含在集合中时更改我的迭代变量的值。
#include <math.h>
int inMandelbrot(int x, int y, int a, int b);
int main(){
const int dimx = 800, dimy = 800;
int x,y;
FILE *mandelbrot;
mandelbrot = fopen("mandelbrot.ppm","w");
fprintf(mandelbrot, "P3\n%d %d\n255\n", dimx, dimy);
for (y=-dimy/2; y< dimy/2 ;++y){
for(x=-dimx/2;x<dimx/2;++x){
if (inMandelbrot(x,y,dimx,dimy)==1){
fprintf(mandelbrot, "0 255 0\n");
}
else if (inMandelbrot(x,y,dimx,dimy)==0){
fprintf(mandelbrot, "0 0 255\n");
}
else if (inMandelbrot(x,y,dimx,dimy)==2){
fprintf(mandelbrot, "225 225 225\n");
}
}
}
(void) fclose(mandelbrot);
return 1;
}
int inMandelbrot(int x, int y, int a, int b){
double xnew,xold,ynew,yold;
double Ex=(x/(a/4));
double Ey=(y/(b/4));
int iterations=0;
xnew=0;
ynew=0;
yold=0;
xold=0;
while((xnew*xnew+ynew*ynew<4)&&(iterations<10000)){
xnew=(xold*xold-yold*yold)+Ex;
ynew=(2*xold*yold)+Ey;
iterations++;
xold=xnew;
yold=ynew;
}
if (xnew*xnew+ynew*ynew>=4){
iterations--;
return 1;
}
else if (iterations>=10000){
return 0;
}
return 2;
}
我希望输出看起来像具有一定精度的 mandelbrot 分形,但是它只有 16 个 200x200“像素”而不是 64000 像素大小的像素。
解决方案
推荐阅读
- hy - 为什么'0是假的,而'假是真的?
- android - 使用 TelephonyManager 拨打外线电话时电话暂停
- node.js - 为什么我们在快速应用程序中需要正文解析器?
- python - wxPython - 检测无输入变化的最佳方法?
- swift - 具有低 alpha 和 subImageView 透明的快速 ImageView 显示父视图但具有 1 个 alpha
- javascript - 在下拉数据之前与 firebase 所有者进行身份验证
- prestashop - Prestashop 1.7:从上下文中获取 Shop Group ID?
- go - minio 客户端 (GO SDK) API 调用不起作用
- javascript - Puppeteer 不会在测试中转到 url(如何清除会话存储 'sessionStorage 未定义')
- email - OroCRM - 如何查看来自 OroCRM 本身的客户回复邮件?