fcnoronha / mandelbrot

📺 Simple Mandelbrot set image generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mandelbrot set image generator

Mandelbrot set

This is an implementation in Golang of a Mandelbrot set image generator. It is based on my previous implementation of such generator, made in C that time.

How it works

As is said in Wikipedia:

The Mandelbrot set is the set of complex numbers c for which the function f(z) = z² + c does not diverge when iterated from z = 0, i.e., for which the sequence f(0), f(f(0)), etc..., remains bounded in absolute value.

For the image to be generated, we take the horizontal axis as the real axis and the vertical axis as the imaginary one. This arrangement lets us take each pixel as a number z = cReal + cImag*i and apply it in the function.

In order to determinate if the function diverge or not we shall use two variables: threshold and nIterations. They tell, respectively, the maximum value the function can assume and the maximum number of iterations of the form f(f(f(...))) can be made. Note that the threshold value passed through command line is the already squared one (default value is 4.0).

Language aspects

The decision of using Golang is based in the facility the language deal with concurrency and parellelism through goroutines. The abstraction and scope heritage provided with go call uppon anonymous functions make this implementation much cleaner than the previous one. Using the argument -nr the user can set the number of goroutines generated inside the function calculateSet.

About

📺 Simple Mandelbrot set image generator


Languages

Language:Go 100.0%