Categories
SMArt Codes

E2C – Butterflying

I’ve decided to leave some of the messiness in – turns out this one is reasonably clean – but some of the upcoming codes are a little messier.

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


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

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

fig, ax = plt.subplots()
#ax.set_xlim(-10000, 10000)
#ax.set_ylim(-10000, 10000)
line, = ax.plot(0,0)
line2, = ax.plot(0,0)
line3, = ax.plot(0,0)
line4, = ax.plot(0,0)
r=1.2
r2=1.5
r3=1.5

count=1
count2=0
count3=0
def animation_frame(i):
    print(i)
    print(np.sin(i))
    x=round(i/30)+0.1
    y4_data.append(x/120*np.sin(i*np.pi/30))
    x4_data.append(x/100*(np.sin(i*np.pi/30/2)*np.sin(i*np.pi/30)))
    x2_data.append(x/100*np.sin(i*np.pi/30))
    y2_data.append(x/100*(np.sin(i*np.pi/30/2)*np.sin(i*np.pi/30))+0.02)
    y_data.append(x/200*np.cos(i*np.pi/30))
    x_data.append(x/300*(np.cos(i*np.pi/30/2)*np.cos(i*np.pi/30)))
    x3_data.append(x/1000*np.sin(i*np.pi/30))
    y3_data.append(abs(x/150*(np.sin(i*np.pi/30)*np.sin(i*np.pi/30))))
    #x4_data.append((x/1000*np.cos(i))+2)
    #y4_data.append((x/1000*np.sin(i))-1.5)
    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)
    line4.set_xdata(x4_data)
    line4.set_ydata(y4_data)
    ax.set_xlim(-0.4,0.4)
    ax.set_ylim(-0.4,0.4)
    line.set_linewidth(1)
    line2.set_linewidth(5)
    line3.set_linewidth(0.5)
    line4.set_linewidth(3)
    line4.set_color('orange')
    line2.set_color('purple')
    line3.set_color('black')
    line.set_color('black')
    return line4,  line, line2, line3

z_data = []
#counter=2000*np.pi
#counter=-300*np.pi
counter=0
for z in range(1, 10000):
    if counter < 10000:
        counter=counter+0.1
    #else:
    #    counter=counter - 300*np.pi
    z_data.append(counter)


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


animation.save('Butterfly2.mp4', dpi=500, bitrate=-1, codec="libx264", extra_args=['-pix_fmt','yuv420p'])
#plt.show()
end = time.time()
print(end - start)
#print("done", "frame=",animation.frame_seq)
Categories
SMArt Codes

E1 – Shell Life

#E1
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

x_data = []
y_data = []

fig, ax = plt.subplots()
ax.set_xlim(-200, 200)
ax.set_ylim(-200,200)
line, = ax.plot(0,0)
r=1.2

def animation_frame(i):
    x_data.append(-r*i*np.cos(i*i)-i*np.cos(i))
    y_data.append(r*i*np.sin(i*i)+i*np.sin(i))

    line.set_xdata(x_data)
    line.set_ydata(y_data)
    line.set_linewidth(0.3)
    return line,


animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, 132, 0.001), interval=40, blit=True)


#animation.save('E1.mp4', dpi=400, bitrate=-1, codec="libx264", extra_args=['-pix_fmt','yuv420p'])
plt.show()
print("done")