Categories
SMArt Codes

E2B – Time To Unwind

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import time

print("starting")
start = time.time()

x_data = []
y_data = []
x2_data = []
y2_data = []
x3_data = []
y3_data = []

fig, ax = plt.subplots()
line, = ax.plot(0,0)
line2, = ax.plot(0,0)
line3, = ax.plot(0,0)
r=1
r2=1.2
r3=1.5

def animation_frame(i):
    print(i)
    x=round(i+1)
    r2=r*(x+1)
    if (((x+1) % 3 == 0)):
        x2_data.append(x*r2*np.cos(i))
        y2_data.append(x*r2*np.sin(i))
    elif ((x % 3 == 0)):
        x_data.append((x*r2*np.cos(i)))
        y_data.append((x*r2*np.sin(i)))
    else:
        x3_data.append((x*r2*np.cos(i)))
        y3_data.append((x*r2*np.sin(i)))
    line.set_xdata(x_data)
    line.set_ydata(y_data)
    line2.set_xdata(x2_data)
    line2.set_ydata(y2_data)
    line3.set_xdata(x3_data)
    line3.set_ydata(y3_data)
    line.set_linewidth(1)
    line2.set_linewidth(0.3)
    line3.set_linewidth(0.3)
    ax.set_xlim(-(i+1)*(i+1),(i+1)*(i+1))
    ax.set_ylim(-(i+1)*(i+1),(i+1)*(i+1))
    line.set_color('orange')
    line2.set_color('purple')
    line3.set_color('green')
    return line, line2, line3

z_data = []
count=0
for z in range(1, 4000):
    count=(count+z)/3
    z_data.append(count)


animation = FuncAnimation(fig, func=animation_frame, frames=z_data, interval=10, blit=True)

animation.save('TimeToUnwind.mp4', dpi=500, bitrate=-1, codec="libx264", extra_args=['-pix_fmt','yuv420p'])
#plt.show()
end = time.time()
print(end - start)

By Kasimir Gregory

PhD Candidate at the University of Newcastle investigating specific-ion effects.
https://scholar.google.com.au/citations?user=O65PgjUAAAAJ&hl=en&oi=ao

Leave a Reply

Your email address will not be published. Required fields are marked *