matlab分形曼德勃罗,曼德勃罗集合分形图案

三、曼德勃罗集合(Mandelbrot Set)

曼德勃罗集合(Mandelbrot Set)或曼德勃罗复数集合,是一种在复平面上组成分形的点的集合,因由曼德勃罗提出而得名。曼德博集合可以使复二次多项式

c097c98fa7a8f342f6ffe6c01236bc9c.png 进行迭代来获得。其中,c是一个复参数。对于每一个c,从 z = 0 开始对fc(z)进行迭代。序列

779a56119f04a9f3f85478d8bee62959.png 的值或者延伸到无限大,或者只停留在有限半径的圆盘内(这与不同的参数c有关)。曼德布洛特集合就是使以上序列不延伸至无限大的所有c点的集合。

最后,我们给出一个利用C语言生成Mandelbrot集合并绘制图形的程序(该程序来自文献【1】):

#include

#include

#include

#define width_size 800

#define height_size 600

#define Maxval 255

static const float orig_x = width_size * 2/3;

static const float orig_y = height_size * 1/2;

static const pixel dim_gray = { 105, 105, 105 };

typedef struct _pixel {

unsigned char r;

unsigned char g;

unsigned char b;

} pixel;static unsigned char iteration(int x, int y)

{

const int limit = Maxval + 1;

int i;

complex c = ((x - orig_x) / (width_size / 3)) +

((orig_y - y) / (height_size / 2)) * I;

complex z = 0;

for (i = 0; i < limit; i++) {

/* basic formula */

z = z * z + c;

if (creal(z) > 2 || cimag(z) > 2)

break;

}

return (unsigned char) (i == limit ? 0 : i);

}

int main()

{

FILE *f = fopen("mandelbrot.ppm", "w+");

/* PPM header */

fprintf(f,

"P6\n" /* PPM magic number */

"#Mandelbrot Set\n"

"%d " /* width, in ASCII decimal */

"%d\n" /* height, in ASCII decimal */

"%d\n", /* maximum color value, in ASCII decimal */

width_size, height_size, Maxval);

/* Write every pixel generated by Mandelbrot Set */

for (int i = 0; i < height_size; i++) {

for (int j = 0; j < width_size; j++) {

unsigned char iter = iteration(j, i);

if (iter) {

pixel p = {

.r = iter,

.g = (float) abs(j - orig_x) / width_size * Maxval,

.b = (float) abs(i - orig_y) / height_size * Maxval };

fwrite(&p, sizeof(pixel), 1, f);

} else {

fwrite(&dim_gray, sizeof(pixel), 1, f);

}

}

}

fclose(f);

return 0;

}

上述程序所生成的图像结果如下图所示,需要补充说明的是:该图像文件格式为ppm,在Windows下你可以使用Photoshop来查看这种类型的图像文件,在OS X系统下你可以使用免费的GIMP软件来查看它。

72c1ff4326e30825f74820afbdef4a83.png

标签:unsigned,int,曼德勃罗,height,图案,width,分形,pixel,size

来源: https://www.cnblogs.com/seeby/p/13754372.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值