Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Mandelbrot set
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Computer drawings== {{Main|Plotting algorithms for the Mandelbrot set}} There exist a multitude of various algorithms for plotting the Mandelbrot set via a computing device. Here, the naïve<ref>{{Cite book |last1=Jarzębowicz |first1=Aleksander |url=https://books.google.com/books?id=mQDsEAAAQBAJ |title=Software, System, and Service Engineering: S3E 2023 Topical Area, 24th Conference on Practical Aspects of and Solutions for Software Engineering, KKIO 2023, and 8th Workshop on Advances in Programming Languages, WAPL 2023, Held as Part of FedCSIS 2023, Warsaw, Poland, 17–20 September 2023, Revised Selected Papers |last2=Luković |first2=Ivan |last3=Przybyłek |first3=Adam |last4=Staroń |first4=Mirosław |last5=Ahmad |first5=Muhammad Ovais |last6=Ochodek |first6=Mirosław |date=2024-01-02 |publisher=Springer Nature |isbn=978-3-031-51075-5 |pages=142 |language=en}}</ref> "escape time algorithm" will be shown, since it is the most popular<ref>{{Cite book |last=Katunin |first=Andrzej |url=https://books.google.com/books?id=lmlQDwAAQBAJ |title=A Concise Introduction to Hypercomplex Fractals |date=2017-10-05 |publisher=CRC Press |isbn=978-1-351-80121-8 |pages=6 |language=en}}</ref> and one of the simplest algorithms.<ref>{{Cite book |last=Farlow |first=Stanley J. |url=https://books.google.com/books?id=r0QI5DMr6WAC |title=An Introduction to Differential Equations and Their Applications |date=2012-10-23 |publisher=Courier Corporation |isbn=978-0-486-13513-7 |pages=447 |language=en}}</ref> In the escape time algorithm, a repeating calculation is performed for each ''x'', ''y'' point in the plot area and based on the behavior of that calculation, a color is chosen for that pixel.<ref>{{Cite book |last=Saha |first=Amit |url=https://books.google.com/books?id=EvWbCgAAQBAJ |title=Doing Math with Python: Use Programming to Explore Algebra, Statistics, Calculus, and More! |date=2015-08-01 |publisher=No Starch Press |isbn=978-1-59327-640-9 |pages=176 |language=en}}</ref><ref>{{Cite book |last=Crownover |first=Richard M. |url=https://books.google.com/books?id=RG3vAAAAMAAJ |title=Introduction to Fractals and Chaos |date=1995 |publisher=Jones and Bartlett |isbn=978-0-86720-464-3 |pages=201 |language=en}}</ref> The ''x'' and ''y'' locations of each point are used as starting values in a repeating, or iterating calculation (described in detail below). The result of each iteration is used as the starting values for the next. The values are checked during each iteration to see whether they have reached a critical "escape" condition, or "bailout". If that condition is reached, the calculation is stopped, the pixel is drawn, and the next ''x'', ''y'' point is examined. The color of each point represents how quickly the values reached the escape point. Often black is used to show values that fail to escape before the iteration limit, and gradually brighter colors are used for points that escape. This gives a visual representation of how many cycles were required before reaching the escape condition. To render such an image, the region of the complex plane we are considering is subdivided into a certain number of [[pixel]]s. To color any such pixel, let <math>c</math> be the midpoint of that pixel. Iterate the critical point 0 under <math>f_c</math>, checking at each step whether the orbit point has a radius larger than 2. When this is the case, <math>c</math> does not belong to the Mandelbrot set, and color the pixel according to the number of iterations used to find out. Otherwise, keep iterating up to a fixed number of steps, after which we decide that our parameter is "probably" in the Mandelbrot set, or at least very close to it, and color the pixel black. In [[pseudocode]], this algorithm would look as follows. The algorithm does not use complex numbers and manually simulates complex-number operations using two real numbers, for those who do not have a [[complex data type]]. The program may be simplified if the programming language includes complex-data-type operations. <!-- NOTE that xtemp is necessary, otherwise y would be calculated with the new x, which would be wrong. Also note that one must plot (''x''<sub>0</sub> ''y''<sub>0</sub>), not (''x'',''y''). --> '''for each''' pixel (Px, Py) on the screen '''do''' x0 := scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.00, 0.47)) y0 := scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1.12, 1.12)) x := 0.0 y := 0.0 iteration := 0 max_iteration := 1000 '''while''' (x^2 + y^2 ≤ 2^2 AND iteration < max_iteration) '''do''' xtemp := x^2 - y^2 + x0 y := 2*x*y + y0 x := xtemp iteration := iteration + 1 <!-- keep the following line filled with trailing whitespace to insert blank line in pseudocode block --> color := palette[iteration] plot(Px, Py, color) Here, relating the pseudocode to <math>c</math>, <math>z</math> and <math>f_c</math>: * <math>z = x + iy</math> * <math>z^2 = x^2 +i2xy - y^2</math> * <math>c = x_0 + i y_0</math> and so, as can be seen in the pseudocode in the computation of ''x'' and ''y'': * <math>x = \mathop{\mathrm{Re}} \left(z^2+c \right) = x^2-y^2 + x_0</math> and <math>y = \mathop{\mathrm{Im}} \left(z^2+c \right) = 2xy + y_0</math>. To get colorful images of the set, the assignment of a color to each value of the number of executed iterations can be made using one of a variety of functions (linear, exponential, etc.). === Python code === Here is the code implementing the above algorithm in [[Python (programming language)|Python]]:<ref>{{Cite web |date=2018-10-03 |title=Mandelbrot Fractal Set visualization in Python |url=https://www.geeksforgeeks.org/mandelbrot-fractal-set-visualization-in-python/ |access-date=2025-03-23 |website=GeeksforGeeks |language=en-US}}</ref>{{close paraphrasing inline|date=March 2025}} <syntaxhighlight lang="numpy"> import numpy as np import matplotlib.pyplot as plt # Setting parameters (these values can be changed) x_domain, y_domain = np.linspace(-2, 2, 500), np.linspace(-2, 2, 500) bound = 2 max_iterations = 50 # any positive integer value colormap = "nipy_spectral" # set to any matplotlib valid colormap func = lambda z, p, c: z**p + c # Computing 2D array to represent the Mandelbrot set iteration_array = [] for y in y_domain: row = [] for x in x_domain: z = 0 p = 2 c = complex(x, y) for iteration_number in range(max_iterations): if abs(z) >= bound: row.append(iteration_number) break else: try: z = func(z, p, c) except (ValueError, ZeroDivisionError): z = c else: row.append(0) iteration_array.append(row) # Plotting the data ax = plt.axes() ax.set_aspect("equal") graph = ax.pcolormesh(x_domain, y_domain, iteration_array, cmap=colormap) plt.colorbar(graph) plt.xlabel("Real-Axis") plt.ylabel("Imaginary-Axis") plt.show() </syntaxhighlight> [[File:Multibrot set of power 5.png|thumb|An image of a 2-dimensional multibrot-set represented by the equation <math>z=z^5+c</math>.]] The value of <code>power</code> variable can be modified to generate an image of equivalent [[multibrot set]] (<math>z = z^{\text{power}}+c</math>). For example, setting <code>p = 2</code> produces the associated image.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)