Skip to content

Commit 5fb1a5a

Browse files
committed
added option to animate in 4k
fixes #2
1 parent c13b03a commit 5fb1a5a

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

solar_system.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
yukawa_coeff=1.5e15, # Yukawa potential coefficient
3333
plot_orbits=True, # plot the orbits
3434
project_orbits_2d=True, # plot the orbits on the bottom
35-
project_2d=True # project on the bottom of the grid
35+
project_2d=True, # project on the bottom of the grid
36+
high_res_plot=True, # enable high resolution simulation plot
37+
fig_4k=True # use 4k resolution
3638
)
3739

3840

@@ -166,26 +168,26 @@ def compute(self):
166168
self._positions = y[:num_bodies * 3].reshape((num_bodies, 3, -1))
167169
self._velocities = y[num_bodies * 3:].reshape((num_bodies, 3, -1))
168170

169-
def create_axes(self, ax):
171+
def create_axes(self, ax, scale):
170172
ax.grid(True)
171173
ax.set_facecolor((1.0, 1.0, 1.0, 0.0))
172174
ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
173175
ax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
174176
ax.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
175177
plt.rcParams['lines.dashed_pattern'] = [20, 20]
176178
ax.xaxis._axinfo['grid'].update(
177-
{"linewidth": 0.1, "color": (0, 0, 0), 'linestyle': '--'})
179+
{"linewidth": scale * 0.5, "color": (0, 0, 0), 'linestyle': '--'})
178180
ax.yaxis._axinfo['grid'].update(
179-
{"linewidth": 0.1, "color": (0, 0, 0), 'linestyle': '--'})
181+
{"linewidth": scale * 0.5, "color": (0, 0, 0), 'linestyle': '--'})
180182
ax.zaxis._axinfo['grid'].update(
181-
{"linewidth": 0.1, "color": (0, 0, 0), 'linestyle': '--'})
183+
{"linewidth": scale * 0.5, "color": (0, 0, 0), 'linestyle': '--'})
182184

183185
ax.xaxis.line.set_color((0.0, 0.0, 0.0, 1.0))
184-
ax.xaxis.line.set_linewidth(1.0)
186+
ax.xaxis.line.set_linewidth(scale * 1.0)
185187
ax.yaxis.line.set_color((0.0, 0.0, 0.0, 1.0))
186-
ax.yaxis.line.set_linewidth(1.0)
188+
ax.yaxis.line.set_linewidth(scale * 1.0)
187189
ax.zaxis.line.set_color((0.0, 0.0, 0.0, 1.0))
188-
ax.zaxis.line.set_linewidth(1.0)
190+
ax.zaxis.line.set_linewidth(scale * 1.0)
189191
ax.set_xlabel('', fontsize=10)
190192
ax.set_ylabel('', fontsize=10)
191193
ax.set_zlabel('', fontsize=10)
@@ -211,12 +213,18 @@ def format_func(value, tick_number):
211213

212214
def animate(self):
213215
self._perc = 0
214-
if cfg.save_anim:
215-
fig = plt.figure(figsize=(12, 8), dpi=300)
216+
dpi = 300 if (cfg.high_res_plot and not cfg.save_anim) else 100
217+
if cfg.fig_4k:
218+
figsize = (3840 / dpi, 2160 / dpi)
219+
scale1 = 4.0
220+
scale2 = 20.0
216221
else:
217-
fig = plt.figure(figsize=(12, 8))
222+
figsize = (1920 / dpi, 1080 / dpi)
223+
scale1 = 1.0
224+
scale2 = 1.0
225+
fig = plt.figure(figsize=figsize)
218226
ax = fig.add_subplot(111, projection='3d')
219-
self.create_axes(ax)
227+
self.create_axes(ax, scale1)
220228
self._scat = []
221229
self._scat2 = []
222230
distances = [np.linalg.norm(body.position) for body in self._bodies]
@@ -225,13 +233,13 @@ def animate(self):
225233
self._scat.append(
226234
ax.scatter([body.position[0]], [body.position[1]],
227235
[body.position[2]],
228-
color=body.color, s=body.mass_plot,
236+
color=body.color, s=scale2 * body.mass_plot,
229237
label=body.name, marker='o', zorder=index))
230238
if cfg.project_2d:
231239
self._scat2.append(
232240
ax.scatter([body.position[0]], [body.position[1]],
233241
-self.axs_limit,
234-
color=(.5, .5, .5), s=body.mass_plot,
242+
color=(.5, .5, .5), s=scale2 * body.mass_plot,
235243
label=body.name, marker='o', zorder=index))
236244
if cfg.plot_orbits:
237245
x_positions = self._positions[index, 0, :]
@@ -242,13 +250,13 @@ def animate(self):
242250
z_positions = self._positions[index, 2, :]
243251
ax.plot(
244252
x_positions, y_positions, z_positions,
245-
color=(.5, .5, .5), linewidth=0.8)
253+
color=(.5, .5, .5), linewidth=scale1 * 0.8)
246254
ax.set_xlim(-self.axs_limit, self.axs_limit)
247255
ax.set_ylim(-self.axs_limit, self.axs_limit)
248256
ax.set_zlim(-self.axs_limit, self.axs_limit)
249257
scat_legend_handles = [scatter for scatter in self._scat]
250-
ax.legend(handles=scat_legend_handles, fontsize=20, loc='upper right',
251-
bbox_to_anchor=(1.2, 1), frameon=False)
258+
ax.legend(handles=scat_legend_handles, fontsize=scale1 * 20,
259+
loc='upper right', bbox_to_anchor=(1.2, 1), frameon=False)
252260

253261
def animate_frame(frame):
254262
if cfg.verbose:

0 commit comments

Comments
 (0)