Skip to content

Make Newton Fractals only with a polynomial with complex coefficients. The program approximates the roots using the Durand Kerner Method. The output image is in .bmp format.

Notifications You must be signed in to change notification settings

All23tor/MakeNewtonFractals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Make Newton Fractals

Screenshot 2024-03-01 202801

Make a Newton Fractal by inputting the coefficients of a polynomial. All the possibly complex roots are found using the Durand-Kerner algorithm.

Header files

The main code uses three header files which define the behaviour of polynomials, colors and fractals.

Polynomial.hpp

Polynomials are represented by a list of their coefficients starting with the constant coefficient and ending with the leading coefficient. The polynomial is evaluated using the Horner method and its roots are found using the Durand-Kerner algorithm, which by dufault uses 60 iterations. Polynomials also support differentiation, which is done by aplying the power ruleto each term.

Color.hpp

Colors are simply three bytes, one for red, one for green, and one for blue. Each byte is stored in an unsigned char. Colors can also be picked by hue instead of RGB, though as it is the implementation is rather ugly. Colors support being scaled by a real number, which just scales each of the three values accordingly.

NewtonFractal.hpp

Newton Fractals are made by aplying Newtons Method at each point and calculating which root it is closest to, then coloring the corresponding pixel according to a color list. By default the width and height of the resulting image is 1600x900, and the range of the real axis is form -5 to 5, the maximum amount of Newton iterations is 200, and the minimum ditance required for a point to be associated with a root is 10 -6. The eccentricity defines how fast the colors descend into black as they take more iterations to reach a root. When the colors for each root are not inputted manually, the Newton Fractal takes as many colors evenly spaced by hue as are necesary. The class generates a .bmp with a BITMAPINFOHEADER DIB header.

Compile and Run

The main.cpp file when compiled makes a simple implementation of the above headers, that only allows for the colors to be inputted manually if desired, every other value is set to default, and the resulting image is stored in a folder called BMPs.

Input

The first value it will ask for is the degree of the polynomial, then it will as for the list of the coefficients. Real number coefficients can be formatted as they would normally be, however complex number coefficients must be formatted like this: (Real(z),Imag(z)) This is enough information to calculate the roots of this polynomial. When the roots are found it will inform this on the console. Then it asks you if you want to choose the colors manually, if so, one must enter as many colors as there are solutions to the polynomial. Once colors are assignated it will inform this on the console. Then the common mathematical representation of the polynomial is printed. Finally it will ask the name of the .bmp file that it is going to generate.

Screenshot 2024-03-12 235520

Complex4thDegree2

About

Make Newton Fractals only with a polynomial with complex coefficients. The program approximates the roots using the Durand Kerner Method. The output image is in .bmp format.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages