added everything else
89
Python/julia.py
Normal file
@@ -0,0 +1,89 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.animation as animation
|
||||
|
||||
import time
|
||||
#from matplotlib import cm
|
||||
#from matplotlib.colors import ListedColormap, LinearSegmentedColormap
|
||||
|
||||
#ncmap = cm.get_cmap('magma', 400)
|
||||
|
||||
|
||||
def julia_quadratic(zx, zy, cx, cy, threshold):
|
||||
"""Calculates whether the number z[0] = zx + i*zy with a constant c = x + i*y
|
||||
belongs to the Julia set. In order to belong, the sequence
|
||||
z[i + 1] = z[i]**2 + c, must not diverge after 'threshold' number of steps.
|
||||
The sequence diverges if the absolute value of z[i+1] is greater than 4.
|
||||
|
||||
:param float zx: the x component of z[0]
|
||||
:param float zy: the y component of z[0]
|
||||
:param float cx: the x component of the constant c
|
||||
:param float cy: the y component of the constant c
|
||||
:param int threshold: the number of iterations to considered it converged
|
||||
"""
|
||||
# initial conditions
|
||||
z = complex(zx, zy)
|
||||
c = complex(cx, cy)
|
||||
|
||||
for i in range(threshold):
|
||||
z = z**2 + c
|
||||
if abs(z) > 4.: # it diverged
|
||||
return i
|
||||
|
||||
return threshold - 1 # it didn't diverge
|
||||
|
||||
|
||||
x_start, y_start = -2, -2 # an interesting region starts here
|
||||
width, height = 4, 4 # for 4 units up and right
|
||||
density_per_unit = 200 # how many pixles per unit
|
||||
|
||||
# real and imaginary axis
|
||||
re = np.linspace(x_start, x_start + width, width * density_per_unit )
|
||||
im = np.linspace(y_start, y_start + height, height * density_per_unit)
|
||||
|
||||
|
||||
threshold = 100 # max allowed iterations
|
||||
frames = 15 # number of frames in the animation
|
||||
|
||||
# we represent c as c = r*cos(a) + i*r*sin(a) = r*e^{i*a}
|
||||
r = 0.7885
|
||||
a = np.linspace(0, 2*np.pi, frames)
|
||||
|
||||
fig = plt.figure(figsize=(10, 10)) # instantiate a figure to draw
|
||||
ax = plt.axes() # create an axes object
|
||||
|
||||
def animate(i):
|
||||
start = time.time()
|
||||
n = i
|
||||
ax.clear() # clear axes object
|
||||
ax.set_xticks([]) # clear x-axis ticks
|
||||
ax.set_yticks([]) # clear y-axis ticks
|
||||
|
||||
X = np.empty((len(re), len(im))) # the initial array-like image
|
||||
cx, cy = r * np.cos(a[i]), r * np.sin(a[i]) # the initial c number
|
||||
|
||||
# iterations for the given threshold
|
||||
for i in range(len(re)):
|
||||
for j in range(len(im)):
|
||||
X[i, j] = julia_quadratic(re[i], im[j], cx, cy, threshold)
|
||||
|
||||
img = ax.imshow(X.T, interpolation="bicubic", cmap="magma")
|
||||
|
||||
end = time.time()
|
||||
diff = end - start
|
||||
global total_time
|
||||
total_time += diff
|
||||
ave = total_time/(n+1)
|
||||
print(f"time[{n}]: {diff:.3f} ETA: {((frames - n+1)* ave)/60:.2f}")
|
||||
return [img]
|
||||
|
||||
start = time.time()
|
||||
|
||||
total_time = 0
|
||||
print("start")
|
||||
|
||||
anim = animation.FuncAnimation(fig, animate, frames=frames, interval=1, blit=True)
|
||||
#writervideo = animation.FFMpegWriter(fps=60)
|
||||
#anim.save('julia_set_vid.mp4', writer=writervideo)
|
||||
anim.save('julia_set_ahhhh.mp4', writer='imagemagick')
|
||||
print("done")
|
BIN
Python/julia_set.gif
Normal file
After Width: | Height: | Size: 2.6 MiB |
BIN
Python/julia_set1.gif
Normal file
After Width: | Height: | Size: 493 KiB |
BIN
Python/julia_set2.gif
Normal file
After Width: | Height: | Size: 322 KiB |
BIN
Python/julia_set3.gif
Normal file
After Width: | Height: | Size: 5.3 MiB |
BIN
Python/julia_set_twilight.gif
Normal file
After Width: | Height: | Size: 2.0 MiB |
BIN
Python/julia_set_twilight0.gif
Normal file
After Width: | Height: | Size: 3.8 MiB |
BIN
Python/julia_set_twilight2.gif
Normal file
After Width: | Height: | Size: 2.2 MiB |
BIN
Python/julia_set_twilight_noblit.gif
Normal file
After Width: | Height: | Size: 2.5 MiB |
BIN
Python/mandelbrot.gif
Normal file
After Width: | Height: | Size: 829 KiB |
BIN
Python/mandelbrot1.gif
Normal file
After Width: | Height: | Size: 916 KiB |
58
Python/untitled-2.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.animation as animation
|
||||
|
||||
def mandelbrot(x, y, threshold):
|
||||
"""Calculates whether the number c = x + i*y belongs to the
|
||||
Mandelbrot set. In order to belong, the sequence z[i + 1] = z[i]**2 + c
|
||||
must not diverge after 'threshold' number of steps. The sequence diverges
|
||||
if the absolute value of z[i+1] is greater than 4.
|
||||
|
||||
:param float x: the x component of the initial complex number
|
||||
:param float y: the y component of the initial complex number
|
||||
:param int threshold: the number of iterations to considered it converged
|
||||
"""
|
||||
# initial conditions
|
||||
c = complex(x, y)
|
||||
z = complex(0, 0)
|
||||
|
||||
for i in range(threshold):
|
||||
z = z**2 + c
|
||||
if abs(z) > 4.: # it diverged
|
||||
return i
|
||||
|
||||
return threshold - 1 # it didn't diverge
|
||||
|
||||
|
||||
x_start, y_start = -2, -1.5 # an interesting region starts here
|
||||
width, height = 3, 3 # for 3 units up and right
|
||||
density_per_unit = 250 # how many pixles per unit
|
||||
|
||||
# real and imaginary axis
|
||||
re = np.linspace(x_start, x_start + width, width * density_per_unit )
|
||||
im = np.linspace(y_start, y_start + height, height * density_per_unit)
|
||||
|
||||
fig = plt.figure(figsize=(10, 10)) # instantiate a figure to draw
|
||||
ax = plt.axes() # create an axes object
|
||||
|
||||
def animate(i):
|
||||
print(i)
|
||||
ax.clear() # clear axes object
|
||||
ax.set_xticks([]) # clear x-axis ticks
|
||||
ax.set_yticks([]) # clear y-axis ticks
|
||||
|
||||
X = np.empty((len(re), len(im))) # re-initialize the array-like image
|
||||
threshold = round(1.25**(i + 1)) # calculate the current threshold
|
||||
|
||||
# iterations for the current threshold
|
||||
for i in range(len(re)):
|
||||
for j in range(len(im)):
|
||||
X[i, j] = mandelbrot(re[i], im[j], threshold)
|
||||
|
||||
# associate colors to the iterations with an iterpolation
|
||||
img = ax.imshow(X.T, interpolation="bicubic", cmap='Reds')
|
||||
return [img]
|
||||
|
||||
anim = animation.FuncAnimation(fig, animate, frames=45, interval=16, blit=True)
|
||||
anim.save('mandelbrot.gif',writer='imagemagick')
|
||||
print("Done")
|