/
Pi=3.141 vs. Pi=3.144 Square Circle Race.py
144 lines (105 loc) · 5.33 KB
/
Pi=3.141 vs. Pi=3.144 Square Circle Race.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.patches import Rectangle
from scipy import signal
import matplotlib.image as mpimg
fig, (ax0,ax, ax2) = plt.subplots(1,3, figsize=(16,9), gridspec_kw={'width_ratios': [1, 2, 1]})
xdata, ydata = [0], [500]
#Set axis plots equal
ax.set_aspect('equal')
ax2.set_aspect('equal')
ax2.set_facecolor("none")
ax0.set_facecolor("none")
ax0.axis('off')
ax2.axis('off')
#Size plot
ax.set_xlim(-600, 600)
ax.set_ylim(-600, 600)
ax0.set_xlim(0, 12)
ax0.set_ylim(12,0)
#plot finish line
ax.plot([0,0],[0,600], color='black', marker='o', linestyle='-',
linewidth=1, markersize=0 ,zorder=-10 )
ax.plot([-600,600],[0,0], color='lightgray', marker='o', linestyle='-',
linewidth=1, markersize=0 ,zorder=-10 )
ax.plot([0,0],[-600,0], color='lightgray', marker='o', linestyle='-',
linewidth=1, markersize=0 ,zorder=-10 )
#Circle with radius 500 plot markers
circle= plt.Circle((0,0),500, color='red', fill=False)
circle_ani = plt.Circle((0,50000),10, color='red', fill=True)
circle_aq = plt.Circle((0,50000),10, color='red', fill=False)
label_circ_ani = ax0.scatter([10000], [10000], marker='o', s=100, facecolors='red', edgecolors='red', alpha=1.00, label=r"Circle:")
#Plot circles Circle 500 radius
ax.add_patch(circle)
ax.add_patch(circle_ani)
ax.add_patch(circle_aq)
#Square Golden ratio s=sqrt(1/phi)
s=1000/np.sqrt((np.sqrt(5)+1)/2)
rect = Rectangle((-np.sqrt(2)*s/2,0),s,s,linewidth=1,edgecolor='blue',facecolor='none', angle=-45)
rect_circ = plt.Circle((0,10000+s/2),10, color='blue', fill=True)
label_circ = ax0.scatter([10000], [10000], marker='o', s=100, facecolors='blue', edgecolors='blue', alpha=1.00, label=r"")
rect_aq = plt.Circle((0,10000+s/2),10, color='blue', fill=False, alpha=0.25)
label_aq_ani = ax0.scatter([10000], [10000], marker='o', s=100, facecolors='none', edgecolors='red', alpha=1.00, label=r"Circle:")
label_aq = ax0.scatter([10000], [10000], marker='o', s=100, facecolors='none', edgecolors='blue', alpha=1, label=r"Linear: $")
# Add the patch to the Axes
ax.add_patch(rect)
ax.add_patch(rect_circ)
ax.add_patch(rect_aq)
#Animation
frames=31
interval=1000/60
rounds=100
#Pi Aquarian Analyst
pi_aq=4/1000*s
#Time message box
timebox=ax.annotate("",(-590,-590), fontsize=16)
print((rounds * ( (frames-1)*(interval/1000 ) ) ))
#Set angular speeds standard and pi=3.144
speed_circ=np.pi*2*500/( ( (frames-1)*(interval/1000 ) ) )
speed_aq=pi_aq*2*500/( ( (frames-1)*(interval/1000 ) ) )
#Animation loop
def update(frame):
#Determnie coordinates standard pi on circle
x=500*np.sin(frame*np.pi)
y=500*np.cos(frame*np.pi)
#Determine coordinates alt pi=3.144 on circle
x_aq=500*np.sin(frame*pi_aq)
y_aq=500*np.cos(frame*pi_aq)
#Plot dots on circle
circle_ani.set_center((x, y))
circle_aq.set_center((x_aq, y_aq))
time=1/rounds*frame/2* (frames-1)*(interval/1000 )
rnds=frame/2
#Plot dots on square standard pi
distance_circ=speed_circ*frame/2* (frames-1)*(interval/1000 )
yr_circ= -np.sqrt(2)*s/2*signal.sawtooth(1/(4*s)*distance_circ*2*np.pi, 0.5)
xr_circ= -np.sqrt(2)*s/2*signal.sawtooth(1/(4*s)*(distance_circ-s)*2*np.pi, 0.5)
rect_circ.set_center((xr_circ, yr_circ))
label_circ.set_label("Square $\pi$: \nDistance: "+ str("{:09.2f}".format((distance_circ))) + "\nSpeed: " + str("{:.4f}".format(round(distance_circ/time,4)) ) +"\n" )
label_circ_ani.set_label("Circle $\pi$: \nDistance: "+ str("{:09.2f}".format((distance_circ)))+ "\nSpeed: " + str("{:.4f}".format(round(distance_circ/time,4)) +"\n" ) )
#Plots dots on square pi=3.144
distance_aq=speed_aq*frame/2* (frames-1)*(interval/1000 )
yr_aq= -np.sqrt(2)*s/2*signal.sawtooth(1/(4*s)*distance_aq*2*np.pi, 0.5)
xr_aq= -np.sqrt(2)*s/2*signal.sawtooth(1/(4*s)*(distance_aq-s)*2*np.pi, 0.5)
rect_aq.set_center((xr_aq, yr_aq))
label_aq_ani.set_label("Circle $4/ \sqrt{\phi}$: \nDistance: "+ str("{:09.2f}".format((distance_aq)))+ "\nSpeed: " + str("{:.4f}".format(round(distance_aq/time,4)) +"\n" ) )
label_aq.set_label("Square $4/ \sqrt{\phi}$: \nDistance: "+ str("{:09.2f}".format((distance_aq)))+ "\nSpeed: " + str("{:.4f}".format(round(distance_aq/time,4)) +"\n" ) )
#Update timebox and legend
timebox.set_text("\nTime: " + str("{:.4f}".format(time,4)) + " seconds\nRounds: " + str("{:.2f}".format(rnds)) + " of " + str(int(rounds)) +" rounds" )
legend = ax0.legend(loc='center right', edgecolor="none", fontsize=16,markerfirst=False)
return rect_aq, rect_circ, circle_ani,timebox, legend,circle_aq
#No animation
ID=np.linspace(2*rounds,rounds*2, frames)
#With animation:
#ID=np.linspace(0,rounds*2, frames)
final=np.full(( int(15/(interval/1000) ) ),ID[-1])
ID=np.append(ID, final)
plt.tight_layout()
anim = animation.FuncAnimation(fig, update, frames=ID, interval=interval, blit=True, repeat=False )
#Save video
#f = r"c://temp/500 s 60 fps 100 rounds Aquarian OOOVincentOOO.avi"
#writervideo = animation.FFMpegWriter(fps=1000/interval)
#anim.save(f, writer=writervideo, dpi = 300)
plt.show()
print("finished")