概述

mandelbrot

julia

Mandelbrot

对全体复数z,满足xn+1 =  xn2 + z从x0 = 0起,|x|随n值增加不趋于无穷大,则z属于Mandelbrot集

代码

#include <glut.h>

int g_width, g_height;

/*********************************
input: z = a + bi
MaxIteration,迭代次数上限
output: 灰度级n
*********************************/
int GrayLevel(double a, double b, int MaxIteration)
{
double x = , y = , xx = , yy = ;
int n = ;
while(n++ < MaxIteration)
{
y = * x * y + b;
x = xx - yy + a;
xx = x * x;
yy = y * y;
if ((xx + yy) > )
{
return n;
}
}
return ;
} void myDisplay()
{
double min_a, max_a, min_b, max_b, step_a, step_b, a, b;
int MaxIteration = ;
int Iteration;
float scale = 255.0 / MaxIteration;
int x,y;
min_a = -2.0;
max_a = 0.5;
min_b = -1.25;
max_b = 1.25;
step_a = (max_a - min_a) / g_width;
step_b = (max_b - min_b) / g_height; glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
a = min_a;
for (x = ; x < g_width; x++)
{
b = min_b;
for (y = ; y < g_height; y++)
{
Iteration = - scale * GrayLevel(a, b, MaxIteration);
glColor3ub(Iteration, Iteration, Iteration);
glVertex2i(x, y);
b += step_b;
}
a += step_a;
}
glEnd();
glFlush();
} void reshape(GLsizei width, GLsizei height)
{
float w_aspect = 4.0 / 3.0;
float aspect = ((float)width) / height; g_width = width;
g_height = height; if (aspect <= w_aspect)
{
glViewport(, (height - width / w_aspect) / ,
width, width / w_aspect);
} else
glViewport((width - height * w_aspect) / , ,
height * w_aspect, height); glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-0.0, 400.0, -0.0, 300.0);
} void main(int argc, char* *argv)
{
glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowSize(, ); glutInitWindowPosition(, ); glutCreateWindow("Mandelbort"); glClearColor(0.0, 0.0, 0.0, 0.0); glutDisplayFunc(&myDisplay); glutReshapeFunc(reshape); glutMainLoop();
}

结果如下

Julia集

在xn+1 =  xn2 + z,对给定的复数z,所有使|x|不发散的x0属于Julia集

给定的z = -0.7454 + 0.1131i;x0的实部为[-1.6,1.6],虚部为[-1.2,1.2]

代码

#include <glut.h>

int g_width, g_height;

/*********************************
输入: z = a + bi
MaxIteration,迭代次数上限
输出: 灰度级n, 0表示白色
思路:
*********************************/
int GrayLevel(double x, double y, int MaxIteration)
{
double xx, yy, zx = -0.7454, zy = 0.1131;
int n = ;
xx = x * x;
yy = y * y;
while(n++ < MaxIteration)
{
y = * x * y + zy;
x = xx - yy + zx;
xx = x * x;
yy = y * y;
if ((xx + yy) > )
{
return n;
}
}
return ;
}

结果如下:

Mandelbrot和Julia的更多相关文章

  1. leaflet地图库

    an open-source JavaScript libraryfor mobile-friendly interactive maps Overview Tutorials Docs Downlo ...

  2. 混沌分形之朱利亚集(JuliaSet)

    朱利亚集合是一个在复平面上形成分形的点的集合.以法国数学家加斯顿·朱利亚(Gaston Julia)的名字命名.我想任何一个有关分形的资料都不会放过曼德勃罗集和朱利亚集.这里将以点集的方式生成出朱利亚 ...

  3. Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical

    http://julialang.org/ julia | source | downloads | docs | blog | community | teaching | publications ...

  4. 在天河二号上对比Julia,Python和R语言

    Julia是一款高级高效为技术计算(technical computing)而设计的编程语言,其语法与其他计算环境类似.其为分布式计算和并行所设计,最知名的地方在于其接近C语言的高效率. 按开发者的话 ...

  5. 使用OpenGL进行Mandelbrot集的可视化

    Mandelbrot集是哪一集?? Mandelbrot集不是哪一集!! 啊不对-- Mandelbrot集是哪一集!! 好像也不对-- Mandelbrot集是数集!! 所以--他不是一集而是数集? ...

  6. [原创+分享]Mandelbrot Explorer

    Mandelbrot Explorer 是一款用于在MandelBort集/Julia集上进行无限漫游的软件,使用VS2013+CUDA6.5开发而成.它也是我学习CUDA开发的一个小小的成果,欢迎大 ...

  7. OpenCV绘制朱利亚(Julia)集合图形

    朱利亚集合是一个在复平面上形成分形的点的集合.以法国数学家加斯顿·朱利亚(Gaston Julia)的名字命名. 朱利亚集合可以由下式进行反复迭代得到: 对于固定的复数c,取某一z值(如z = z0) ...

  8. 数量经济学推荐的Julia教程

    http://quant-econ.net/jl/learning_julia.html Julia最为号称和c媲美的运行速度,想python一下简单的语法,虽然发展还不完善,但任然值得去关注. Ju ...

  9. julia的优化?

    julia> function fib1(n) if n==1 return n else return n+fib1(n-1) end end fib1 (generic function w ...

随机推荐

  1. Spark Streaming源码解读之流数据不断接收全生命周期彻底研究和思考

    本期内容 : 数据接收架构设计模式 数据接收源码彻底研究 一.Spark Streaming数据接收设计模式   Spark Streaming接收数据也相似MVC架构: 1. Mode相当于Rece ...

  2. openldap主机访问控制(基于hostname)

    http://mayiwei.com/2013/03/21/centos6-openldap/ http://www.zytrax.com/books/ldap/ch11/dynamic.html h ...

  3. margin:0 auto在IE中失效的解决方案

    转自:http://www.cnblogs.com/hongchenok/archive/2012/11/29/2795041.html 最近在开发项目的时候,发现在火狐浏览器中设置外容器margin ...

  4. NHibernate系列文章十六:使用程序集管理NHibernate项目(附程序下载)

    摘要 在实际的项目中,经常是将NHibernate的实体关系映射类做成独立的工程(assembly dll),只对外提供Session调用的接口.这个程序集作为数据访问层,可以被上面的多个工程(ASP ...

  5. js按Enter键提交表单

    function exprint(e){ /* var keycode = event.keyCode; if (keycode == "13"){ fm.UserCode.foc ...

  6. singleTask, singleInstance使用心得

    1. singleTask, singleInstance 共同点: 1)  一旦入栈,都为于栈底. 2) 全栈有且只有一个activity实例对象. 2. singleTask, singleIns ...

  7. ORACLE 回收站导致的故障

    ORACLE 回收站导致的故障 一.故障 (1)现象     一个生产环境,oracle数据库挂死,严重影响生产.查死锁sql,发现大量日志插入语句,并且每条运行时间都超过一分钟,插入非常缓慢.据分析 ...

  8. 设置PATH变量

    一不小心把PATH变量清空了,所有的命令都执行不了了,提示“xxx: command not found”,解决办法:在命令行输入export PATH=/usr/local/sbin:/usr/lo ...

  9. bash脚本编程之二 条件判断and 逻辑运算

    1.条件测试结构 1) if/then结构: 判断命令列表的退出码是否为0,0为成功. 如果if和then在条件判断的同一行上的话, 必须使用分号来结束if表达式: if和then都是关键字. 关键字 ...

  10. 【MVC】 js,css 压缩

    [MVC] js,css 压缩 一. 引用 System.Web.Optimization.dll : 使用 Nuget ,在控制台输入 Install-Package Microsoft.AspNe ...