import numpy as np
import matplotlib.pyplot as plt
class Complex:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
temp = Complex(self.x + other.x, self.y + other.y)
return temp
def __mul__(self, other):
newx = self.x * other.x - self.y * other.y
newy = self.x * other.y + self.y * other.x
temp = Complex(newx, newy)
return temp
def __str__(self):
return str([self.x, self.y])
def size(self):
return (self.x**2 + self.y**2)**0.5
z1 = Complex(2,3)
z2 = Complex(1,2)
print(z1 + z2)
print(z1 * z2)
z = Complex(0.8, 0.2)
for i in range(0, 5):
z = z * z
print(z)
z1 = Complex(0.8,0.2)
z2 = Complex(-.7,0.25)
z3 = Complex(1,0.1)
xlist1, ylist1 = [z1.x], [z1.y]
xlist2, ylist2 = [z2.x], [z2.y]
xlist3, ylist3 = [z3.x], [z3.y]
for i in range(0, 5):
z1 = z1 * z1
z2 = z2 * z2
z3 = z3 * z3
xlist1.append(z1.x), ylist1.append(z1.y)
xlist2.append(z2.x), ylist2.append(z2.y)
xlist3.append(z3.x), ylist3.append(z3.y)
fig=plt.figure(figsize=(8, 8))
plt.plot(xlist1, ylist1, marker='.', markersize=10)
plt.plot(xlist2, ylist2, marker='.', markersize=10)
plt.plot(xlist3, ylist3, marker='.', markersize=10)
plt.plot([-2,2], [0,0], c='black', linewidth=1)
plt.plot([0,0], [-2,2], c='black', linewidth=1)
plt.xlim(-1.2,1.2)
plt.ylim(-0.5,1.2)
plt.show()
xgrid = [0,1,2,3]
ygrid = [0,1,2,3]
shade = [[0,0,0],[0,1,1],[0,2,3]]
for row in shade:
print(row)
my_cmap = plt.get_cmap('coolwarm')
#cmap = plt.get_cmap('plasma')
#cmap = plt.get_cmap('nipy_spectral')
#cmap = plt.get_cmap('spring_r')
plt.close()
plt.figure(figsize = (2,2), dpi=200)
plt.pcolormesh(xgrid, ygrid, shade, cmap=my_cmap)
#plt.axis('off')
plt.colorbar()
plt.show()
def julia(c, iter = 200, res = 100, pal=0):
xgrid = np.array(range(-2*res,2*res))/res
ygrid = np.array(range(-2*res,2*res))/res
iterations = []
for i in range(-2*res,2*res):
row = []
y = i / res
for j in range(-2*res,2*res):
x = j / res
z = Complex(x,y)
for n in range(1,iter + 1):
z = z * z + c
if(z.size() > 2):
break
row.append(n)
iterations.append(row)
palettes = [plt.get_cmap('plasma'), plt.get_cmap('nipy_spectral'),
plt.get_cmap('coolwarm'), plt.get_cmap('spring_r')]
cmap = palettes[pal]
plt.close()
plt.figure(figsize = (4,4), dpi=200)
plt.pcolormesh(xgrid, ygrid, iterations,cmap = cmap)
plt.axis('off')
plt.show()
c = Complex(0, 0)
julia(c)
c = Complex(-0.75, 0)
julia(c)
c = Complex(-0.75, 0.1)
julia(c)
c = Complex(-0.75, 0.1)
julia(c, iter=400)
c = Complex(-0.1, 0.8)
julia(c, iter=300, pal=1)
c = Complex(-0.1, 0.9)
julia(c, iter=300, pal=1)
c = Complex(-0.4, 0.5)
julia(c, iter=300, pal=2)
c = Complex(-0.4, 0.6)
julia(c, iter=300, pal=2)
c = Complex(0.36, 0.10)
julia(c, res=200, iter=400, pal=0)
c = Complex(0.36, 0.11)
julia(c, res=200, iter=400, pal=0)