-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclifford_bound_zoom_9090.py
85 lines (65 loc) · 2.71 KB
/
clifford_bound_zoom_9090.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! Python3
# A program that displays an evolution of the clifford attractor
# using Euler's formula with deliberately large values of delta_t
# combined with a quiver plot, iterating over larger and larger
# values of delta_t. Produces a series of .png images that can be
# assembled into a movie.
# import third party libraries
import numpy as np
import matplotlib.pyplot as plt
import copy
def clifford_attractor(x, y, a=-1.4, b=1.7, c=1.0, d=0.7):
'''Returns the change in arguments x and y according to
the Clifford map equation. Kwargs a, b, c, and d are specified
as constants.
'''
x_next = np.sin(a*y) + c*np.cos(a*x)
y_next = np.sin(b*x) + d*np.cos(b*y)
return x_next, y_next
def clifford_boundary(max_iterations, t, a=-1.4, b=1.7, c=1.0, d=0.7):
x_range = 3000
y_range = 3000
x_list = np.arange(-4/(2**(t/15)) + 91.82168, 4/(2**(t/15)) + 91.82168, (8/(2**(t/15)))/x_range)
y_list = np.arange(4/(2**(t/15)) + 90.47914, -4/(2**(t/15)) + 90.47914, -(8/(2**(t/15)))/y_range)
array = np.meshgrid(x_list[:3000], y_list[:3000])
x2 = np.zeros(x_range)
y2 = np.zeros(y_range)
iterations_until_in_basin = np.meshgrid(x2, y2)
for i in iterations_until_in_basin:
for j in i:
j += max_iterations
not_already_in_basin = iterations_until_in_basin[0] < 10000
for k in range(max_iterations):
array_copied = copy.deepcopy(array[0]) # copy array to prevent premature modification of x array
# henon map applied to array
array[0] = array[0] + (1.35)*(np.sin(a*array[1]) + c*np.cos(a*array[0]))
array[1] = array[1] + (1.35)*(np.sin(b*array_copied) + d*np.cos(b*array[1]))
# note which array elements are diverging,
in_basin = np.abs(array[0] - 91) + np.abs(array[1] - 92.5) < 2
entering_basin = in_basin & not_already_in_basin
iterations_until_in_basin[0][entering_basin] = k
not_already_in_basin = np.invert(entering_basin) & not_already_in_basin
return iterations_until_in_basin[0]
# differential trajectory
for t in range(300):
# number of iterations
iterations = 100000
delta_t = 1.35
# initialization
X = np.zeros(iterations)
Y = np.zeros(iterations)
# starting point
(X[0], Y[0]) = (11.3, 8.5)
# euler's method for tracking differential equations
for i in range(iterations-1):
x_next, y_next = clifford_attractor(X[i], Y[i])
X[i+1] = X[i] + x_next * delta_t
Y[i+1] = Y[i] + y_next * delta_t
plt.style.use('dark_background')
plt.plot(X, Y, ',', color='white', alpha = 0.2, markersize = 0.1)
plt.imshow(clifford_boundary(30 + t//15, t), extent=[-4/(2**(t/15)) + 91.82168, 4/(2**(t/15)) + 91.82168, -4/(2**(t/15)) + 90.47914, 4/(2**(t/15)) + 90.47914], cmap='twilight', alpha=1)
plt.axis('off')
plt.show()
# plt.savefig('{}.png'.format(t), dpi=400, bbox_inches='tight')
plt.close()
break