Digital Rangoli! (Newton fractals, actually)

This year, on the occasion of Diwali, I decided I will make Rangoli digitally!

x6 + x3 - 1 (30 iterations)

I wrote a program to calculate and draw the generalized Newton fractal for a given polynomial. The fractal pattern arises from the fact that for some initial values, the Newton-Raphson method is very sensitive. This image is a map of the behaviour of each point on the complex plane (when it is chosen as starting point) under this method.

Lets go over the details part-by-part.

Newton-Raphson Method:

Given a function f(x) and a complex number z_0, the series of numbers z_{n+1} = z_n - \frac{f(z_n)}{f'(z_n)} either converges towards a root of the function (called an attractor), or does not show convergent behaviour.

Most complex numbers produce a convergent series. Numbers in each other’s vicinity usually converge to the same root, but in some areas, nearby points reach different roots. When each complex number is coloured by the root it is attracted to, interesting plots are obtained. These plots display fractal like boundaries and similar patterns appear on zooming further.

Colouring Criteria:

The Hue (h), Saturation (s) and Lightness(l) of any point on the graph is determined by:

h = 180\frac{\theta + \pi}{\pi}s = 0.75l = \frac{1}{2} - \frac{n}{2m}, where \theta is the argument of the root the point reaches, n is the number of steps in which the point got within \epsilon of the root and m is the maximum iterations allowed. If the point does not show convergence within the maximum number of iterations or the derivative is zero, then the point is coloured black.

Corollary: Points that have same colour, converge to the same root.

\epsilon is around 0.0001 and m is 30 for the following images. The plotting area is -3.2 to +3.2 on the real axis and -1.8 to 1.8 on the imaginary axis.

Click on images to zoom in.

x8 + 15x4 - 16 (30 iterations)

f(z) = z^8 + 15z^4 - 16

x8 + 15x4 - 16 (100 iterations) (zoom)

A closeup of an intricate region of the above graph.

x6 + x3 - 1 (30 iterations)

f(z) = z^6 + z^3 - 1

x3 - 2x + 2 (30 iterations)

f(z) = z^3 - 2z +2

x3 - 1 (30 iterations)

f(z) = z^3 - 1

The program is written in C++. You can find the source code here:

Currently, you need to update the source code with you plotting parameters (look for comments in the main function on how to do so) and then compile it (I used Visual Studio ’15 but GCC works as well). I am working on a way to enter the parameters through a text file (like Mandelbrot Set Plotter) or through command line. Have fun with the program!

If you have any feedback, leave a comment or contact me at

Wishing you a Happy and Safe Diwali! 🙂

Free Educational Resources on Volunteer DVD – August 2016 Edition

Edit: My article is featured in the MIT BLOSSOMS News:

MIT BLOSSOMS – An Unprecedented Learning Opportunity


This is what my DVD looks like!


I happened to come across the MIT BLOSSOMS website while searching for world-class online enrichment opportunities over the net. This free resource has over 175 math and science videos for teachers for use in high school classrooms. However, I got interested in these videos as the topics were closely related to our high school curriculum. I was pretty excited to have discovered this online treasure and started watching these videos on my own, at my home, one by one.

I have prepared a collection of free, high-quality educational resources and have burned them on a DVD for distribution to other learners. This DVD has 25 selected videos from the MIT BLOSSOMS library, NCERT Exemplar Problems books on math & science for relevant theory, and links to some excellent educational websites like edX, MIT OpenCourseWare, Khan Academy, etc. that offer free learning resources. The learners have the flexibility to watch the videos at a time and place they find convenient; they can watch them over and over again to understand the concepts better.

A special thanks of mine goes to Madam Elizabeth Murray, Project Manager of the MIT BLOSSOMS Initiative, whose support and encouragement made this DVD possible.


Mandelbrot Set! (GitHub link included!)

GitHub – Mandelbrot Set

UPDATE: I have now written a Zoom Sequence Generator driver program. With that, you can create videos like and Visit the GitHub repository to know more!

The MandelBrot Set is “a particular set of complex numbers which has a highly convoluted fractal boundary when plotted.” Mathematically speaking, define a sequence z such that: latex_6fd6b1325fe1f8910391ee6566d5c53b and latex_27ae09541f9c34b36225d5e11bc47613Then the Mandelbrot set is the set of all numbers c such that latex_aaaddd7a521e9e243910ec57306d9ff5

I have written a program in C++ that generates a .bmp image of the required coordinates of the Mandelbrot Set! It is fully customizable in terms of:

  • Region of the set you want (real coordinates, imaginary coordinates)
  • Number of iterations
  • Colour of the image

You can enter commands for many images at once. It is up for download and/or testing on GitHub here. Right now, I am working on the shading algorithm for the colors. (Currently, I am using a quartic polynomial shading, which tends to make images purple-ish) Here are some cool images from the program:


lightning mini_mandel200 full_pinksample3The entire Mandelbrot Set.

(RealAxis -2 to 1, ImaginaryAxis -1 to 1, 50 iterations per pixel)


A part of the fractal that resembles lightning bolts.

(RealAxis -0.04 to -0.03, ImaginaryAxis 0.98 to 0.99, 50 iterations per pixel)


Many smaller copies of the entire structure exists inside the main structure. This is one of them.

(RealAxis -1.420 to -1.415, Imaginary Axis -0.0025 to 0.0025, 200 iterations per pixel)


The entire Mandelbrot Set rendered in pink.

(RealAxis -2 to 1, ImaginaryAxis -1 to 1, 50 iterations per pixel)

An “elephant trunk” from the “elephant valley”

(RealAxis 0.27707 to 0.28165, ImaginaryAxis 0.00627 to 0.01085, 200 iterations per pixel)



Some other images-

You will find the input commands for all these images over at github.

sample5 sample6

I have also made an animated GIF of the 3rd image above, as the iteration count goes from 50 to 200. Please be patient while it loads, as it is a rather large image (around 50MB). View it here. (Bluish bands around the boundaries are compression artifacts)


PerAte – My new programming language!

Recently, I have been working on designing a new programming language, that I decided to call “PerAte”. Its now Turing complete and functional! I have uploaded its interpreter and documentation here (GitHub). So far, I have made several programs in it such as Factorial, String I/O, etc. As a proof of concept, I wrote a primality check program in it. Please check it out!

But there is a lot to be done, and it is under continuous development.