Mandelbrot
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:This repository consists of a SAD app to render the Mandelbrot set.
# Introduction
This repository consists of a SAD app to render the Mandelbrot set.

# The Mandelbrot set
The Mandelbrot set, hereon referred to as `the set', is a mathematical set of points in the complex plane, the boundary of which forms a fractal. 

Named after the mathematician Benoît Mandelbrot, who studied and popularized it, more formally, it is the set of complex numbers `c` for which the orbit of 0 under iteration of the complex quadratic polynomial `Z(n+1) = Z(n)\*\*2 + c` remains bounded as `n` tends to infinite. That is, a complex number `c` is part of the set if, when starting with `Z(0) = 0` and applying the iteration repeatedly, the absolute value of `Z(n)` remains bounded however large `n` gets. 

For example, letting `c = 1` gives the sequence `0, 1, 2, 5, 26,…,` which tends to infinity. As this sequence is unbounded, `1` is not an element of the set. 

On the other hand, `c = i` (where i is defined as i\*\*2 = −1) gives the sequence `0, i, (−1 + i), −i, (−1 + i), −i, ...,` which is bounded, and so `i` belongs to the set. 

The set has a distinctive and easily recognizable two-dimensional fractal shape. Images of the set display an elaborate boundary that reveals progressively ever-finer recursive detail at increasing magnifications. The _style_ of this repeating detail depends on the region of the set being examined. The set's boundary also incorporates smaller versions of the main shape, so the fractal property of self-similarity applies to the entire set, and not just to its parts. 

# The Mandelbrot set and computers
When computed and graphed on the complex plane the set is seen to have an elaborate boundary which, being a fractal, does not simplify at any given magnification.The set has become popular outside mathematics both for its aesthetic appeal and for being a complicated structure arising from a simple definition, and is one of the best-known examples of mathematical visualization. 
 
Mathematically, the set is just a set of complex numbers. A given complex number `c` either belongs to the set or it does not. A picture of the set can be made by coloring all the points `c` which belong to the set black, and all other points white. The more colorful pictures usually seen are generated by coloring points not in the set according to how quickly or slowly the sequence diverges to infinity.
 
# Why another program to render the Mandelbrot set
What is the point of writing another yet another program to graph the set? This article chronicles my experience in writing a software program to graph the set. There are countless documented examples of such attempts; therefore I do not plan to break any new ground, except to do something I enjoy quite a bit which is to write software while exploring new technologies.In this particular case my goal is to write this program using the new `HTML 5 Canvas` element.

# The solution
The essence of this solution lies in dealing two distinct spaces:

1. The complex numbers being assessed for set membership
2. The drawing canvas being used to represent these numbers M/S membership. Members are rendered in black. Non members are rendered in color. The color used to render non-members correlates to the number of iterations required to assess membership
 
## The complex numbers
Graphing the set amounts to selecting a complex number region and assessing the complex numbers in it for membership in the set. For practical purposes we will define this region as a rectangle, as follows:

1. center (iCenter): the center of the rectangle containing the complex numbers
2. height (iHeight): the height of the rectangle
3. width (iWidth): the width of the rectangle

Therefore, the complex numbers under consideration fit in to the following rectangle:

1. NW = x = iCenter.x - iWidth/2, y = iCenter.x + iHeight/2
2. NE = x = iCenter.x + iWidth/2, y = iCenter.x + iHeight/2
3. SE = x = iCenter.x + iWidth/2, y = iCenter.x - iHeight/2
4. SW = x = iCenter.x - iWidth/2, y = iCenter.x - iHeight/2
   
## The drawing canvas
The graphing will be rendered onto a computer screen. The screen area used build the graph is called a canvas and, not surprisingly, will be a rectangle, described as follows:

1. selector (cSelector): the id of the HMTL canvas object. Since the complex set we are drawing fits within a rectangle, our canvas is also a rectangle. All the canvas coordinates are based on its NW corner
2. height (cHeight): the height of the canvas
3. width (cWidth): the width of the canvas

Therefore, the canvas used to represent the complex numbers under consideration fit in to the following rectangle:

1. NW = x = 0     , y = 0  
2. NE = x = cWidth, y = 0
3. SE = x = cWidth,  y = cHeight
4. SW = x = 0     ,  y = cHeight
   
## Sampling the complex numbers
The quantity of complex numbers within any region is infinite whereas the number of pixels in the canvas where their set membership is graphed is finite. This requires a mechanism to select and render a subset of the complex numbers under consideration. The complex numbers will be selected based on the proportion between their rectangle height and width and that of the canvas square. Given a selected complex number `c = m + in, (m, n in R)`, `c'`, the next complex number
to be considered will be `c' = (m + xStep) + i(n + yStep)` where:

1. xStep = iWidth/cWidth
2. yStep = iHeight/cHeigth
   
## Assessing membership
It has been demonstrated that if the absolute value of an iteration exceeds `2` the seed complex number does not belong to the set; thus, when assessing membership of a complex number `c`, if at a given iteration the absolute value of `c'`, one of the iteration terms, exceeds `2`, `c` will be assessed as not being a member. Given a complex number `c = m + n*i, n, m in R`, its absolute value is `sqrt(m**2 + n**2)`; in order to simplify and speed up calculations, if at a given iteration the power of two of absolute value of `c'`, one of the iteration terms, exceeds `4`, `c` will be assessed as not being a member   
   
The only remaining item for consideration is the number of iterations,`n`, to be considered before membership is granted. I have no idea at the moment and will use a random number; I envision learning about it experimentally; perhaps using a iterative method where, given a set of complex numbers, starting with a certain number of iterations and measuring the number of `c` that are in the set, we increase the number of iterations and compare the quantity, `q`, members; once `q` stabilizes, we know we have an acceptable `n`.

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。