C++C++11C++14C++17Language FeatureLearn C++

Tutorial: Easily Learn To Draw Mandelbrot In C++ On Windows

In mathematics, Fractals are a self-similar subset of Euclidean space whose fractal dimensions strictly exceeds its topological dimension. So when you draw these functions in their topological height, fractals appear the same at different levels, as illustrated in successive magnifications of the Mandelbrot set.

Mandelbrot set is a good example to see how fractals are changing in every x,y and z planes. Drawing a Mandelbrot set exhibit an elaborate and infinitely complicated boundary that reveals progressively ever-finer recursive details at increasing zooming that makes the boundary of the Mandelbrot set as in fractal curves. The Mandelbrot set basically defined as a function of f(z)=z^2+c where z and c are complex numbers.

C++ Builder is easy to draw or print these kind of graphics, it includes compilers for Win32, Win64, Android and iOS. C++Builder has both CLANG Enhanced C/C++ Compiler and a Borland C/C++ Compiler. It also features a modern, high-productivity RAD Studio IDE, debugger tools, and enterprise connectivity for to accelerate cross-platform UI development. You can develop GUI based applications easily, as it comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs. There is a free C++ Builder Community Edition that can be used by students, beginners and startups with limitations.

You can download Free the C++ Builder Community Edition (CE) here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. You can download and use the trial version for one month with the same capabilities as the full version . Please visit https://www.embarcadero.com/products/cbuilder.

This Mandelbrot_to_bitmap procedure directly draws Mandelbrot fractal to a bitmap in given iterations. In this example we try as simple as possible.

In this post we want to draw a Mandelbrot set into Canvas of a Bitmap in C++ Builder. It is presented that Mandelbrot can be drawn in text form as in here (link***).

1.Create a new Multi-Device C++ Builder (FMX) project, Save all unit and project files into a folder.

2. Add a Button (TButton) and an Image (TImage) to show final bitmap.

3. Double click to Button and modify lines as below;

Here we defined a very basic color spectrum ( spec[] ) and we try to keep drawing pixels simple. We are sure you will enjoy to survey drawing this better. Also you can find more fractal examples on VCL here. I think it is easy to convert to FMX version as in given example above.

Note that spec[], color spectrum array can be done outside of mandelbrot_to_bitmap() as a global or public in a class;

and this line

which setups color spectrum array can be defined outside of mandelbrot_to_bitmap() to speed up this function. You can also directly draw to Image1->Bitmap without doing Assign() and Free(). Iterations and some other coding techniques may also speed up calculation and drawing durations. This simple code do all you need in one procedure.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?