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

E2A – Passiflora

#E2_A
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 = []

fig, ax = plt.subplots()
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5,1.5)
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/500)r2=r*(x+1)if ((x % 2 == 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/500+1)*(i/500+1),(i/500+1)*(i/500+1))
    ax.set_ylim(-(i/500+1)*(i/500+1),(i/500+1)*(i/500+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, 6500):count=count+2.2z_data.append(count)


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


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