code: 
  
  
  
  
  
  
  from __future__ import annotations
  
  import random
  
  from matplotlib import animation
  from matplotlib import pyplot as plt
  
  # Frame rate of the animation
  __snake_case							      =						20
  
  # Time between time steps in seconds
  __snake_case							      =						INTERVAL / 10_00
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
  						"""simple docstring"""
  						def __init__(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_ = 1.0					,       SCREAMING_SNAKE_CASE_ = 1.0					,       SCREAMING_SNAKE_CASE_ = "blue"					,       )       ->   None:
  										UpperCamelCase :int										=     position_x
  										UpperCamelCase :List[Any]										=     position_y
  										UpperCamelCase :Tuple										=     velocity_x
  										UpperCamelCase :Optional[Any]										=     velocity_y
  										UpperCamelCase :Optional[Any]										=     mass
  										UpperCamelCase :Union[str, Any]										=     size
  										UpperCamelCase :Any										=     color
  						@property
  						def 					UpperCAmelCase		(       self				)       ->   tuple[float, float]:
  										return self.position_x, self.position_y
  						@property
  						def 					UpperCAmelCase		(       self				)       ->   tuple[float, float]:
  										return self.velocity_x, self.velocity_y
  						def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)       ->   None:
  										self.velocity_x += force_x * delta_time
  										self.velocity_y += force_y * delta_time
  
  
  
  
  						def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_				)       ->   None:
  										self.position_x += self.velocity_x * delta_time
  										self.position_y += self.velocity_y * delta_time
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
  						"""simple docstring"""
  						def __init__(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_ = 1.0					,       SCREAMING_SNAKE_CASE_ = 1.0					,       SCREAMING_SNAKE_CASE_ = 0.0					,       )       ->   None:
  										UpperCamelCase :Tuple										=     bodies
  										UpperCamelCase :Tuple										=     gravitation_constant
  										UpperCamelCase :Any										=     time_factor
  										UpperCamelCase :Any										=     softening_factor
  						def __len__(       self				)       ->   int:
  										return len(self.bodies				)
  
  
  
  
  						def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_				)       ->   None:
  										for bodya in self.bodies:
  														UpperCamelCase :Optional[Any]										=     0.0
  														UpperCamelCase :str										=     0.0
  														for bodya in self.bodies:
  																		if bodya != bodya:
  																						UpperCamelCase :List[str]										=     bodya.position_x - bodya.position_x
  																						UpperCamelCase :Union[str, Any]										=     bodya.position_y - bodya.position_y
  
  																						# Calculation of the distance using Pythagoras's theorem
  																						# Extra factor due to the softening technique
  																						UpperCamelCase :Dict										=     (dif_x**2 + dif_y**2 + self.softening_factor) ** (
  																						    1 / 2
  																						)
  
  																						# Newton's law of universal gravitation.
  																						force_x += (
  																						    self.gravitation_constant * bodya.mass * dif_x / distance**3
  																						)
  																						force_y += (
  																						    self.gravitation_constant * bodya.mass * dif_y / distance**3
  																						)
  
              # Update the body's velocity once all the force components have been added
  														bodya.update_velocity(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       delta_time * self.time_factor				)
  
  										# Update the positions only after all the velocities have been updated
  										for body in self.bodies:
  														body.update_position(delta_time * self.time_factor				)
  
  
  
  
  
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			BodySystem  ,						SCREAMING_SNAKE_CASE__						:			float  ,						SCREAMING_SNAKE_CASE__						:			list[plt.Circle] ):
  				body_system.update_system(snake_case__ )
  
  				# Update the positions of the patches
  				for patch, body in zip(snake_case__  ,						body_system.bodies ):
  								UpperCamelCase :List[str]										=     (body.position_x, body.position_y)
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			str  ,						SCREAMING_SNAKE_CASE__						:			BodySystem  ,						SCREAMING_SNAKE_CASE__						:			float = -1  ,						SCREAMING_SNAKE_CASE__						:			float = 1  ,						SCREAMING_SNAKE_CASE__						:			float = -1  ,						SCREAMING_SNAKE_CASE__						:			float = 1  ,						):
  				UpperCamelCase :Dict										=     plt.figure()
  				fig.canvas.set_window_title(snake_case__ )
  				UpperCamelCase :Any										=     plt.axes(
  				    xlim=(x_start, x_end)  ,						ylim=(y_start, y_end) )  # Set section to be plotted
  				plt.gca().set_aspect('''equal''' )  # Fix aspect ratio
  
  				# Each body is drawn as a patch by the plt-function
  				UpperCamelCase :List[Any]										=     [
  				    plt.Circle((body.position_x, body.position_y)  ,						body.size  ,						fc=body.color )
  				    for body in body_system.bodies
  				]
  
  				for patch in patches:
  								ax.add_patch(snake_case__ )
  
  				# Function called at each step of the animation
  				def update(SCREAMING_SNAKE_CASE__						:			int ) -> list[plt.Circle]:
  								update_step(snake_case__  ,						snake_case__  ,						snake_case__ )
  								return patches
  
  				UpperCamelCase :Dict										=     animation.FuncAnimation(  # noqa: F841
  				    snake_case__  ,						snake_case__  ,						interval=snake_case__  ,						blit=snake_case__ )
  
  				plt.show()
  
  
  def 						_A     (       ):
  				UpperCamelCase :str										=     0.9_70_04_36
  				UpperCamelCase :Optional[Any]										=     -0.24_30_87_53
  				UpperCamelCase :Optional[int]										=     0.4_66_20_36_85
  				UpperCamelCase :int										=     0.43_23_65_73
  
  				UpperCamelCase :int										=     [
  				    Body(snake_case__  ,						snake_case__  ,						snake_case__  ,						snake_case__  ,						size=0.2  ,						color='''red''' ),
  				    Body(-position_x  ,						-position_y  ,						snake_case__  ,						snake_case__  ,						size=0.2  ,						color='''green''' ),
  				    Body(0  ,						0  ,						-2 * velocity_x  ,						-2 * velocity_y  ,						size=0.2  ,						color='''blue''' ),
  				]
  				return BodySystem(snake_case__  ,						time_factor=3 )
  
  
  def 						_A     (       ):
  				UpperCamelCase :str										=     7.3_4_7_6e2_2
  				UpperCamelCase :str										=     5.9_7_2e2_4
  				UpperCamelCase :Union[str, Any]										=     1022
  				UpperCamelCase :Optional[Any]										=     384399000
  				UpperCamelCase :str										=     6.6_7_4e-1_1
  
  				# Calculation of the respective velocities so that total impulse is zero,
  				# i.e. the two bodies together don't move
  				UpperCamelCase :int										=     earth_mass * velocity_dif / (earth_mass + moon_mass)
  				UpperCamelCase :str										=     moon_velocity - velocity_dif
  
  				UpperCamelCase :Optional[int]										=     Body(-earth_moon_distance  ,						0  ,						0  ,						snake_case__  ,						snake_case__  ,						10000000  ,						'''grey''' )
  				UpperCamelCase :Dict										=     Body(0  ,						0  ,						0  ,						snake_case__  ,						snake_case__  ,						50000000  ,						'''blue''' )
  				return BodySystem([earth, moon]  ,						snake_case__  ,						time_factor=1000000 )
  
  
  def 						_A     (       ):
  				UpperCamelCase :int										=     []
  				for _ in range(10 ):
  								UpperCamelCase :Optional[int]										=     random.uniform(-0.5  ,						0.5 )
  								UpperCamelCase :Union[str, Any]										=     random.uniform(-0.5  ,						0.5 )
  
  								# Bodies are created pairwise with opposite velocities so that the
  								# total impulse remains zero
  								bodies.append(
  								    Body(
  								        random.uniform(-0.5  ,						0.5 )  ,						random.uniform(-0.5  ,						0.5 )  ,						snake_case__  ,						snake_case__  ,						size=0.05  ,						) )
  								bodies.append(
  								    Body(
  								        random.uniform(-0.5  ,						0.5 )  ,						random.uniform(-0.5  ,						0.5 )  ,						-velocity_x  ,						-velocity_y  ,						size=0.05  ,						) )
  				return BodySystem(snake_case__  ,						0.01  ,						10  ,						0.1 )
  
  
  if __name__ == "__main__":
  	plot("""Figure-8 solution to the 3-body-problem""", example_a(), -2, 2, -2, 2)
  	plot(
  	    """Moon\'s orbit around the earth""",
  	    example_a(),
  	    -4_30_00_00_00,
  	    4_30_00_00_00,
  	    -4_30_00_00_00,
  	    4_30_00_00_00,
  	)
  	plot("""Random system with many bodies""", example_a(), -1.5, 1.5, -1.5, 1.5)
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
        """simple docstring"""
        def __init__(       self					,       SCREAMING_SNAKE_CASE_				)       ->   None:
            UpperCamelCase :Tuple										=     value
            UpperCamelCase :Node | None										=     None
            UpperCamelCase :Node | None										=     None
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
        """simple docstring"""
        UpperCamelCase_       :      int
        def __init__(       self				)       ->   None:
            UpperCamelCase :List[Any]										=     0
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)       ->   None:
            if node is None:
                return
  
            if path_sum == self.target:
                self.paths += 1
  
            if node.left:
                self.depth_first_search(node.left					,       path_sum + node.left.value				)
            if node.right:
                self.depth_first_search(node.right					,       path_sum + node.right.value				)
  
  
  
  
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_ = None				)       ->   int:
            if node is None:
                return 0
            if target is not None:
                UpperCamelCase :Tuple										=     target
  
            self.depth_first_search(SCREAMING_SNAKE_CASE_					,       node.value				)
            self.path_sum(node.left				)
            self.path_sum(node.right				)
  
            return self.paths
  
  
  if __name__ == "__main__":
   import doctest
  
   doctest.testmod()
  
  
  
  
  
  