Site icon Learn C++

Tutorial: Learn To Print Mandelbrot In Text Form In C++

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.

In this post we want to show you how you can printout a Mandelbrot set in text form in C++ Builder. While we are able to draw as shown above in graphics we want to have fun with printing it in text form.

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

2. Let’s do as simple as possible. Clear all codes, add these library includes.

[crayon-6605dc0ce0e50138763374/]

3. Now let’s create our own text_mandelbrot(…) function to draw a Mandelbrot set in text form as a console.

[crayon-6605dc0ce0e58935671246/]

As given in here we defined two complex numbers

[crayon-6605dc0ce0e5a360311310/]

We loop in row and column as x and y coordinates, and we calculate height of this function with complex numbers related with these row and column,

[crayon-6605dc0ce0e5c490182646/]

4. Finally we need to define our main function to run our text_mandelbrot(…) function.

[crayon-6605dc0ce0e5d581727452/]

5. Hit F9 to run your codes or run your code from Run button.

That’s all. This simple code compatible with most of C++ compilers, you may need few changes in some compilers. You can improve this code by drawing a part of this function (like zooming to a portion of it). Or you can use Bitmaps and directly draw it with full details. Don’t worry about calculations and speed about to draw these kind of functions in math. Because C++ is faster to calculate and draw these things. You can also use parallel programming methods to use all of your CPU and GPU cores draw anything multiple times faster.

Full Lines of VCL Console Application in C++ Builder should be like this;

[crayon-6605dc0ce0e5f631270029/]

And the result will be like this;

Exit mobile version