Lesson 11 of 15
Mandelbrot Set
Mandelbrot Set
The Mandelbrot set is one of the most famous fractals in mathematics. A complex number c belongs to the set if the sequence defined by:
remains bounded (never escapes to infinity). In practice, we check whether |z| ever exceeds 2 — if it does, the sequence will diverge to infinity.
The escape time algorithm counts how many iterations it takes for |z| to exceed 2. Points inside the set never escape; points outside escape after some number of steps. The number of iterations before escape gives information about how "close to the boundary" a point is, and is used to color the famous fractal images.
Implement the following functions:
mandelbrot_iter(cr, ci, max_iter)— return the number of iterations before |z|² > 4, ormax_iterif the point is in the set. The complex number c = cr + ci·i, z starts at 0.in_mandelbrot(cr, ci, max_iter)— returnTrueif the point is in the Mandelbrot set (did not escape withinmax_iteriterations)mandelbrot_grid(cr_min, cr_max, ci_min, ci_max, nx, ny, max_iter)— count how many grid points in the given rectangle are in the Mandelbrot set
Python runtime loading...
Loading...
Click "Run" to execute your code.