Mandelbrot set is a very interesting set of complex numbers that satisfy a particular property. The complex numbers \(c\) for which the function
\[ f_c(z) = z^2 + c \]
does not diverge into infinity when iterated starting from \(z = 0\), i.e. the function value of \(f_c(0), f_c(f_c(0)), ...\) remains bounded by an absolute value.
Some complex numbers are contained in this set, and some might diverge. By colouring their diverging properties, you can get a very beautiful picture!
The code for plotting this graph is listed as follows. This uses a programming language called Processing.
# Change to regions of interestx_MIN,x_MAX=-0.78,-0.73y_MIN,y_MAX=-0.08,-0.03x_RANGE=x_MAX-x_MINy_RANGE=y_MAX-y_MINSCREEN_SIZE=300COUNT=100color_grid=[]# Stores colors for each pixeldefsetup():globalx_scale,y_scale,color_gridsize(SCREEN_SIZE,SCREEN_SIZE)noStroke()colorMode(HSB,360,100,100)x_scale=float(x_RANGE)/(width-1)y_scale=float(y_RANGE)/(height-1)# Precompute colorsforxinrange(width):row=[]foryinrange(height):zx=x_MIN+x*x_scalezy=y_MAX-y*y_scale# Flip Y-axis so y=0 is bottomz=[zx,zy]col=mandelbrot(z,COUNT,bound=2)ifcol==COUNT:c=color(0)else:hue=(200-float(col)/COUNT*360)%360c=color(hue,100,100)row.append(c)color_grid.append(row)defdraw():globalcolor_gridforxinrange(width):foryinrange(height):fill(color_grid[x][y])rect(x,y,1,1)noLoop()# Stop after one drawdefmousePressed():ifmouseButton==LEFT:filename="pattern_x[{},{}]_y[{},{}].tif".format(x_MIN,x_MAX,y_MIN,y_MAX)save(filename)print("Saved to: {}".format(sketchPath(filename)))defmandelbrot(z,num,bound=2):count=0z1=z[:]whilecount<=num:ifcMagnitude(z1)>bound:returncountz1=cAdd(cMult(z1,z1),z)count+=1returnnumdefcAdd(a,b):return[a[0]+b[0],a[1]+b[1]]defcMult(a,b):return[a[0]*b[0]-a[1]*b[1],a[0]*b[1]+a[1]*b[0]]defcMagnitude(a):returnsqrt(a[0]**2+a[1]**2)