-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch file(click to launch simulation).py
125 lines (113 loc) · 3.24 KB
/
launch file(click to launch simulation).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
import matplotlib.pyplot as plt
import matplotlib.animation as anime
import math
import time
import time
import moviepy.editor as mp
from PIL import Image
import glob
import webbrowser;
s1 = 180
s2 = 0
t1 = 60
ct = 1
filename = ''
x1 = 100*(math.cos(math.radians(t1))) + 200
y1 = 100*(math.sin(math.radians(t1))) + 200
x = 200*(math.cos(math.radians(t1))) + 200
y = 0 + 200
x2 = 100 * (math.cos(math.radians(s1))) + 200
y2 = 50 * (math.sin(math.radians(s1))) + 200
plt.xlim(0, 400)
plt.ylim(0, 400)
plt.plot([200, x1], [200, y1])
plt.plot([x1, x], [y1, y])
print('Simulation is being generated, please wait a few seconds.....')
while t1 < 121:
plt.xlim(0, 400)
plt.ylim(0, 400)
x1 = 100 * (math.cos(math.radians(t1))) + 200
y1 = 100 * (math.sin(math.radians(t1))) + 200
x = 200 * (math.cos(math.radians(t1))) + 200
y = 0 + 200
t1 = t1+6
filename = 'file' + str(ct) + '.png'
ct = ct + 1
plt.plot([200, x1], [200, y1])
plt.plot([x1, x], [y1, y])
plt.savefig(filename)
plt.clf()
ct = ct + 1
filename = 'file' + str(ct) + '.png'
plt.savefig(filename)
while s1 > 0:
plt.xlim(0, 400)
plt.ylim(0, 400)
x1 = 100 * (math.cos(math.radians(t1))) + 200
y1 = 100 * (math.sin(math.radians(t1))) + 200
x2 = 100 * (math.cos(math.radians(s1))) + 200
y2 = 50 * (math.sin(math.radians(s1))) + 200
t1 = t1-4.5
s1 = s1-4.5
filename = 'file' + str(ct) + '.png'
ct = ct + 1
plt.plot([200, x1], [200, y1])
plt.plot([x1, x2], [y1, y2])
plt.savefig(filename)
plt.clf()
ct = ct + 1
filename = 'file' + str(ct) + '.png'
plt.savefig(filename)
while t1 > -121:
plt.xlim(0, 400)
plt.ylim(0, 400)
x1 = 100 * (math.cos(math.radians(t1))) + 200
y1 = 100 * (math.sin(math.radians(t1))) + 200
x = 200 * (math.cos(math.radians(t1))) + 200
y = 0 + 200
t1 = t1-6
filename = 'file' + str(ct) + '.png'
ct = ct + 1
plt.plot([200, x1], [200, y1])
plt.plot([x1, x], [y1, y])
plt.savefig(filename)
plt.clf()
ct = ct + 1
filename = 'file' + str(ct) + '.png'
plt.savefig(filename)
s1 = 180
while s1 > 0:
plt.xlim(0, 400)
plt.ylim(0, 400)
x1 = 100 * (math.cos(math.radians(t1))) + 200
y1 = 100 * (math.sin(math.radians(t1))) + 200
x2 = 100 * (math.cos(math.radians(s1))) + 200
y2 = 50 * (math.sin(math.radians(s1))) + 200
t1 = t1-4.5
s1 = s1-4.5
filename = 'file' + str(ct) + '.png'
ct = ct + 1
plt.plot([200, x1], [200, y1])
plt.plot([x1, x2], [y1, y2])
plt.savefig(filename)
plt.clf()
ct = ct + 1
filename = 'file' + str(ct) + '.png'
plt.savefig(filename)
# Create the frames
frames = []
imgs = glob.glob("*.png")
filename = 'file'
ct = 1
for i in imgs:
new_frame = Image.open(filename + str(ct) + '.png')
ct = ct + 2
frames.append(new_frame)
# Save into a GIF file that loops forever
frames[0].save('Simulation.gif', format='GIF',
append_images=frames[1:],
save_all=True,
duration=5, loop=0)
clip = mp.VideoFileClip("Simulation.gif")
clip.write_videofile("Simulation.mp4")
webbrowser.open('Simulation.mp4')