derek-thomas HF staff commited on
Commit
8683ed3
1 Parent(s): b4f0e09

Trying out the spinner

Browse files
Files changed (1) hide show
  1. disc_golf_simulator.py +36 -39
disc_golf_simulator.py CHANGED
@@ -17,6 +17,10 @@ default_roll = 14.7
17
 
18
  def main():
19
  tab1, tab2 = st.tabs(['Simulator', 'FAQ'])
 
 
 
 
20
  with tab1:
21
  disc_names = {
22
  'Innova Wraith': 'dd2',
@@ -45,55 +49,48 @@ def main():
45
  value=default_pitch,
46
  step=0.1)
47
 
48
- pos = np.array((0, 0, z0))
49
- disc_dict = DiscGolfDisc(disc_name)
 
50
 
51
- stl_mesh = get_stl(proj_dir / 'shotshaper' / 'discs' / (disc_name + '.stl'))
52
- fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
53
 
54
- st.markdown("""## Disc Orientation""")
55
- st.plotly_chart(fig)
56
- st.markdown("""## Flight Path""")
57
- shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
58
- position=pos, nose_angle=nose, roll_angle=roll)
59
 
60
- # Plot trajectory
61
- x, y, z = shot.position
62
- x_new, y_new = -1 * y, x
63
 
64
- # Reversed x and y to mimic a throw
65
- fig = get_plot(x_new, y_new, z)
66
- st.plotly_chart(fig, True)
67
 
68
- st.markdown(
69
- f"""
70
- **Arrows in Blue** show you where your *s-turn* is.
71
 
72
- **Arrows in Red** show you your *max height* and *lateral deviance*.
73
 
74
- Hit Play to watch your animated throw.
75
 
76
- | Metric | Value |
77
- |--------------|--------|
78
- | Drift Left | {round(min(x_new), 2)} |
79
- | Drift Right | {round(max(x_new), 2)} |
80
- | Max Height | {round(max(z), 2)} |
81
- | Distance | {round(max(y_new), 2)} |
82
 
83
- """
84
- )
85
 
86
- arc, alphas, betas, lifts, drags, moms, rolls = disc_dict.post_process(shot, omega)
87
- fig = get_subplots(arc, alphas, lifts, drags, moms, rolls, shot.velocity)
88
- st.plotly_chart(fig, True)
89
-
90
- vb_link = 'https://visitor-badge.glitch.me/badge?page_id=derek-thomas.disc-golf-simulator&left_color=gray&right_color=blue'
91
- visitor_badge = f"![Total Visitors]({vb_link})"
92
- st.markdown(f"""
93
- Thanks for visiting :)
94
-
95
- ![Total Visitors]({vb_link})
96
- """)
97
 
98
  with tab2:
99
  st.markdown("""
 
17
 
18
  def main():
19
  tab1, tab2 = st.tabs(['Simulator', 'FAQ'])
20
+ vb_link = 'https://visitor-badge.glitch.me/badge?page_id=derek-thomas.disc-golf-simulator&left_color=gray&right_color=blue'
21
+ st.sidebar.markdown(f"""
22
+ ![Total Visitors]({vb_link})
23
+ """)
24
  with tab1:
25
  disc_names = {
26
  'Innova Wraith': 'dd2',
 
49
  value=default_pitch,
50
  step=0.1)
51
 
52
+ with st.spinner(text="Calculating Flight Path..."):
53
+ pos = np.array((0, 0, z0))
54
+ disc_dict = DiscGolfDisc(disc_name)
55
 
56
+ stl_mesh = get_stl(proj_dir / 'shotshaper' / 'discs' / (disc_name + '.stl'))
57
+ fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
58
 
59
+ st.markdown("""## Disc Orientation""")
60
+ st.plotly_chart(fig)
61
+ st.markdown("""## Flight Path""")
62
+ shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
63
+ position=pos, nose_angle=nose, roll_angle=roll)
64
 
65
+ # Plot trajectory
66
+ x, y, z = shot.position
67
+ x_new, y_new = -1 * y, x
68
 
69
+ # Reversed x and y to mimic a throw
70
+ fig = get_plot(x_new, y_new, z)
71
+ st.plotly_chart(fig, True)
72
 
73
+ st.markdown(
74
+ f"""
75
+ **Arrows in Blue** show you where your *s-turn* is.
76
 
77
+ **Arrows in Red** show you your *max height* and *lateral deviance*.
78
 
79
+ Hit Play to watch your animated throw.
80
 
81
+ | Metric | Value |
82
+ |--------------|--------|
83
+ | Drift Left | {round(min(x_new), 2)} |
84
+ | Drift Right | {round(max(x_new), 2)} |
85
+ | Max Height | {round(max(z), 2)} |
86
+ | Distance | {round(max(y_new), 2)} |
87
 
88
+ """
89
+ )
90
 
91
+ arc, alphas, betas, lifts, drags, moms, rolls = disc_dict.post_process(shot, omega)
92
+ fig = get_subplots(arc, alphas, lifts, drags, moms, rolls, shot.velocity)
93
+ st.plotly_chart(fig, True)
 
 
 
 
 
 
 
 
94
 
95
  with tab2:
96
  st.markdown("""