Skip to content

Commit ad40ec6

Browse files
committed
Objects are in the scene
1 parent 379bc5b commit ad40ec6

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

example_scenes.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,43 @@ def text_updater(old_text):
677677

678678
class NewtonGravitation2DExample(Scene):
679679
def construct(self) -> None:
680-
pass
680+
# Define properties
681+
n_masses = 3
682+
y0: np.ndarray = np.array(
683+
[
684+
[2, 1, 0], # position of mass1
685+
[-3, 1.5, 0], # position of mass2
686+
[5.5, -2.5, 0], # position of mass3
687+
[2, 0, 0], # velocity of mass1
688+
[0, -2, 0], # velocity of mass2
689+
[-1, 0, 0], # velocity of mass3
690+
]
691+
)
692+
masses: np.ndarray = np.array(
693+
[1, 1, 1]
694+
)
695+
mass_multiplier = 0.35 # multiplier for the radius given a mass
696+
# the fps value can be independent of the real FPS of the animation
697+
t0, T, fps = 0, 5, 30 # may need to rise fps to get better results
698+
t: np.ndarray = np.linspace(t0, T, (T-t0)*fps)
699+
colors: tuple = (RED_E, BLUE, GREEN)
700+
# Create circle mobjects and move them to their initial positions
701+
mass_circles: list[Mobject] = [
702+
Circle(
703+
fill_color=colors[i],
704+
fill_opacity=1,
705+
stroke_width=0,
706+
radius=masses[i]*mass_multiplier
707+
) for i in range(n_masses)
708+
]
709+
# there is no need to slice but for consistency
710+
for circle, pos in zip(mass_circles, y0[:n_masses,:]):
711+
circle.move_to(pos)
712+
713+
# Add circle mobjects to the scene
714+
self.add(*mass_circles)
681715

682716

683717
####################################################################
684-
# eNd: jCode example scenes #
718+
# END: jCode example scenes #
685719
####################################################################

0 commit comments

Comments
 (0)