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.

close

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

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

en_USEnglish