#!/usr/bin/env python # 2017-02-12 Simple Mandelbrot / Julia set example # http://algoristo.com/teaching/ import numpy as np nsteps = 500 maxiter = 100 limit = 2.0 # Floats xmin = -2.0 xmax = 1.0 ymin = -1.5 ymax = 1.5 # Julia set only c = np.complex(0, 1) datfile = open("heatmap.dat", "w") for i in range(nsteps + 1): for j in range(nsteps + 1): x = xmin + i*(xmax - xmin)/nsteps y = ymin + j*(ymax - ymin)/nsteps # Julia #z = np.complex(x, y) # Mandelbrot c = np.complex(x, y) z = np.complex(0) for n in range(maxiter): z = z*z + c if abs(z) > limit: break # Note: starting point x, y, not the result datfile.write("%f %f %f\n" % (x, y, n)) datfile.close()