#!/usr/bin/env python # 2017-02-12 Orbit graph example # http://algoristo.com/teaching/ import math from random import random, choice ninit = 10 niter = 10000 def rotate(x, y, degrees): s = math.sin(math.pi*degrees/180) c = math.cos(math.pi*degrees/180) return c*x - s*y, c*y + s*x # Example: Gingerbreadman map def gingerbread(x, y): # Constants -- try changing these M = 1 L = 0 A = 1 B = 1 return M*(1 + 2*L) - A*y + B*abs(x - L*M), x/A ifs = [gingerbread] datfile = open("orbit.dat", "w") for i in range(1, ninit + 1): # Random point -- needs a wider range than 0 to 1 x = 2*random() y = 2*random() for j in range(1, niter + 1): f = choice(ifs) x, y = f(x, y) # Write each stage of the orbit to the same file datfile.write("%f %f\n" % (x, y)) datfile.close()