#!/usr/bin/env python # 2017-02-12 Simple Mandelbrot / Julia set example # http://algoristo.com/teaching/ import math nsteps = 500 maxiter = 100 # Squared limit = 4.0 # Floats xmin = -2.0 xmax = 1.0 ymin = -1.5 ymax = 1.5 # Julia set only #cx, cy = 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 zx, zy = x, y # Mandelbrot #zx, zy = 0, 0 for n in range(maxiter): # Note both components at once zx, zy = zx**2 - zy**2 + x, 2*zx*zy + y # Wrong order is also interesting #zx = zx**2 - zy**2 + x #zy = 2*zx*zy + y if zx**2 + zy**2 > limit: break # Note: starting point x, y, not the result datfile.write("%f %f %f\n" % (x, y, n)) datfile.close()