-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvis-circ.html
295 lines (260 loc) · 12.7 KB
/
vis-circ.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Astronomy & Python: Circ Motion Vis</title>
<!-- Bootstrap -->
<link href="css/bootstrap-4.4.1.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="css/main.css" rel="stylesheet" type="text/css">
<link rel="icon" href="favicon.png">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<py-env>
- matplotlib
</py-env>
</head>
<body>
<div class="nav-social-wrapper">
<nav class="navbar navbar-expand-md navbar-light astro-navbar">
<div id="navlogo-div"><a class="navbar-brand align-items-center align-self-center" href="index.html"><img id="navlogo" src="images/APLogoNAV.svg" alt="Astronomy and Python Logo"></a></div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item ">
<a class="nav-link navlink" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link navlink" href="about.html">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link navlink dropdown-toggle navbarDropdown" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Get Involved
</a>
<div class="dropdown-menu astro-drop" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="projects.html">Students</a>
<a class="dropdown-item" href="educators.html">Educators</a>
<a class="dropdown-item" href="challenge.html">Challenges</a>
</div>
</li>
<li class="nav-item astro-nav-item">
<a class="nav-link navlink" href="code.html">Code</a>
</li>
<li class="nav-item astro-nav-item">
<a class="nav-link navlink" href="https://github.com/AstroDimitrios/Astronomy">
GitHub <img id="githubLogo" alt="GitHub Logo" src="images/github.svg">
</a>
</li>
<li class="nav-item dropdown astro-nav-item">
<a class="nav-link navlink dropdown-toggle navbarDropdown" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
</a>
<div class="dropdown-menu astro-drop" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="ppt.html">Teaching</a>
<a class="dropdown-item" href="data.html">Data</a>
<a class="dropdown-item" href="fits.html">FITs Processing</a>
<a class="dropdown-item" href="read.html">Reading Lists</a>
<a class="dropdown-item" href="edi.html">EDI & Careers</a>
<a class="dropdown-item" href="visual.html">Visuals</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="social_square_icons">
<ul>
<li id="ytube-list"><a href="https://www.youtube.com/channel/UCf8Sg-cgLNubyCM5Em8eDZg" class="youtube gap"><i class="fa fa-youtube-play" aria-hidden="true"></i></a></li>
<li><a href="https://twitter.com/AstroDimitrios" class="t_twitter gap"><i class="fa fa-twitter" aria-hidden="true"></i></a> </li>
<li><a href="https://www.linkedin.com/in/dimitrios-theodorakis-62b378171/" class="linkedin"><i class="fa fa-linkedin" aria-hidden="true"></i></a> </li>
</ul>
</div>
</div>
<div class="jumbotron jumbotron-fluid text-center subpage-title">
<h1 class="display-4 innerjumbo with-smalltag">Circular Motion Sim</h1>
<p class="smalltag">planet in circular motion</p>
</div>
<div class="container">
<div class="row">
<div class="col-md-8 offset-lg-2">
<p>Simulation showing a planet orbiting the Sun. The centripetal force and velocity arrows are drawn. Made using <a href="https://pyscript.net/" class="astroLinks">PyScript</a>.</p>
</div>
</div>
<br><br>
</div>
<div class="container">
<div class="row">
<div class="col-md-8 offset-lg-2">
<div class="row" id="btn-row">
<div class="btn-sim-div">
<button id="button-back" type="button" class="btn btn-primary btn-sim" pys-onClick="main_play_back">
⏴︎
</div>
<div class="btn-sim-div">
<button id="button-pause" type="button" class="btn btn-primary btn-sim" pys-onClick="main_stop">
⏸︎
</div>
<div class="btn-sim-div">
<button id="button-forward" type="button" class="btn btn-primary btn-sim" pys-onClick="main_play">
⏵︎
</div>
</div>
<div class="row">
<div style="width:15%;">
<p class="center-vis text-center">Angle</p>
</div>
<div style="width:70%; display: flex; align-items: center;">
<input class="center-slider slider slider-var" id="slider-num-var" type="range" min="0" max="360" value="0" step="1" oninput="document.getElementById('angle').value = this.value" style="width:100%;">
</div>
<div style="width:15%;">
<output class="center-vis2" style="float: left; padding-right: 0px;" id="angle">0</output>
<p class="center-vis2" style="float: left; padding-left: 0px;">°</p>
</div>
</div>
<div class="row">
<div id="outputDiv" class="col-md-8 offset-lg-2"></div>
</div>
<div class="row">
<div id="outputHelp" class="col-md-8 offset-lg-2"></div>
</div>
<py-script>
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.axes_grid1
from js import setInterval, clearInterval
from pyodide import to_js
out = Element("outputDiv")
help = Element("outputHelp")
<!-- class Player():
def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
save_count=None, mini=0, maxi=100, **kwargs):
self.i = 0
self.min=mini
self.max=maxi
self.runs = True
self.forwards = True
self.fig = fig
self.func = func
self.setup()
def play(self):
while self.runs:
self.i = self.i+self.forwards-(not self.forwards)
if self.i > self.min and self.i < self.max:
yield self.i
else:
if self.i == self.max:
self.i = self.min
else:
self.i = self.max
def start(self, event=None):
self.runs=True
self.event_source.start()
def stop(self, event=None):
self.runs = False
self.event_source.stop()
def forward(self, event=None):
self.forwards = True
self.start()
def backward(self, event=None):
self.forwards = False
self.start()
def onestep(self):
if self.i > self.min and self.i < self.max:
self.i = self.i+self.forwards-(not self.forwards)
elif self.i == self.min and self.forwards:
self.i+=1
elif self.i == self.max and not self.forwards:
self.i-=1
self.func(self.i)
Element("slider-num-var").write(self.i)
out.write(fig)
def setup(self):
val = Element("slider-num-var").value
self.set_value(val)
def set_value(self,i):
self.i = int(Element("slider-num-var").value)
self.func(self.i)
def update(self,i):
Element("slider-num-var").write(self.i)
fig, ax = plt.subplots(1, 1, dpi=150, figsize=(10,10))
ax.axis("off")
G = 6.67430*10**-11 # m3 kg-1 s-2
AU = 1.496*10**11 # m
m_Sun = 1.989*10**30 # kg
m_Earth = 5.972*10**24 # kg
r = 1
def calc_cent_f(m1, m2, r):
m2 *= m_Earth
r *= AU
return G*m1*m2/r**2
def gen_circle(r):
theta = np.linspace(0, 2*np.pi, 361)
x = r*np.cos(theta) # AU
y = r*np.sin(theta) # AU
return x, y
x, y = gen_circle(r)
fig = plt.figure(num=1, figsize=(10, 10))
lim = r*1.4
ax = plt.axes(xlim=(-lim, lim), ylim=(-lim, lim), projection='3d')
ax.axis("off")
trace = ax.plot(x, y, 0, linestyle="--")
sun = ax.scatter3D(0, 0, 0, s=500, c='gold', zorder=1)
circle, = ax.plot(x[0], y[0], 0, linestyle="", marker="o", zorder=2)
def update(i):
circle.set_data([x[i]], [y[i]])
circle.set_3d_properties([0]) # Update the positions of our balls -->
import datetime
def update_timestamp(elem):
elem.write(
format(datetime.datetime.now(), "%H:%M:%S, %A, %d %B %Y")
)
class Play_Buttons():
def __init__(self):
pass
def start(self):
self.tm = setInterval(
to_js(lambda: update_timestamp(out)),
1000 # Update every 1000 ms
)
def stop(self):
clearInterval(self.tm)
player = Play_Buttons()
def main_play(*ags, **kws):
player.start()
def main_play_back(*ags, **kws):
help.write('Here')
def main_stop(*ags, **kws):
player.stop()
<!-- ani = Player(fig, update, maxi=len(y)-1) -->
</py-script>
<br>
</div>
</div>
<br/>
<br/>
<!--
<div class="row">
<div class=" col-md-4"> Click here to select this<strong> column.</strong> Always place your content within a column. Columns are indicated by a dashed blue line. </div>
<div class="col-md-4 "> You can <strong>resize a column</strong> using the handle on the right. Drag it to increase or reduce the number of columns.</div>
<div class="col-md-4 "> You can <strong>offset a column</strong> using the handle on the left. Drag it to increase or reduce the offset. </div>
</div>
-->
<br>
<hr>
<div class="row">
<div class="text-center col-md-8 offset-md-2">
<!-- <h5>Contact - astrodimitrios(at)gmail.com </h5>-->
<p class="footer-text">Contact - astrodimitrios(at)gmail.com, <br class="brfooter">Copyright Dimitrios Theodorakis © 2021 · GNU GPL 3.0</p>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-3.4.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/popper.min.js"></script>
<script src="js/bootstrap-4.4.1.js"></script>
</body>
</html>