VDampedSpring

Qualified name: manim\_pymunk.constraints.VDampedSpring

class VDampedSpring(a_mob, b_mob, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), rest_length=1.0, stiffness=100.0, damping=10.0, mob_a_appearance=Dot, mob_b_appearance=Dot, connect_line_class=<class 'manim_pymunk.custom_mobjects.v_spring.VSpring'>, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]

Bases: VConstraint

A damped spring connection is created between two rigid bodies. The spring applies a restorative force proportional to the displacement from its rest length, while the damping simulates energy loss to suppress oscillations.

Parameters

a_mob

The first Mobject to be connected. Acts as one of the anchor points for the spring.

b_mob

The second Mobject to be connected. Linked to a_mob via the physical spring constraint.

anchor_a_local

The local anchor point on a_mob where the spring is attached, relative to the Mobject’s center.

anchor_b_local

The local anchor point on b_mob where the spring is attached, relative to the Mobject’s center.

rest_length

The equilibrium length of the spring. When the distance between anchors equals this value, the spring exerts no force.

stiffness

The spring constant $k$ (Young’s modulus). Determines how strongly the spring pulls or pushes to return to rest_length.

damping

The damping coefficient $c$. Used to simulate viscous friction, causing the kinetic energy of the system to dissipate over time.

mob_a_appearance

The Mobject used to visually represent the anchor point on a_mob (e.g., a Dot).

mob_b_appearance

The Mobject used to visually represent the anchor point on b_mob (e.g., a Dot).

connect_line_class

The class used to visualize the spring body (defaults to VSpring). If set to None, the spring connection will be invisible.

connect_line_config

A dictionary defining the visual style of the connect_line_class, such as color and stroke_width.

Examples

Example: VDampedSpringExample

from manim import *

from manim_pymunk import *

class VDampedSpringExample(SpaceScene):
    def construct(self):
        floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2)

        square_1 = Square().next_to(floor, UP)
        square_2 = Square().move_to(square_1.get_center() + UP * 4)

        constraint = VDampedSpring(
            square_1,
            square_2,
            rest_length=3,
            stiffness=100,
            damping=10,
        )

        self.add_static_body(floor)
        self.add_dynamic_body(square_1, square_2)
        self.add_constraints(constraint)

        self.wait(3)
from manim_pymunk import *

class VDampedSpringExample(SpaceScene):
    def construct(self):
        floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2)

        square_1 = Square().next_to(floor, UP)
        square_2 = Square().move_to(square_1.get_center() + UP * 4)

        constraint = VDampedSpring(
            square_1,
            square_2,
            rest_length=3,
            stiffness=100,
            damping=10,
        )

        self.add_static_body(floor)
        self.add_dynamic_body(square_1, square_2)
        self.add_constraints(constraint)

        self.wait(3)

Methods

install

Verify the validity of constraint parameters.

mob_updater

Visual control updater

Attributes

always

Call a method on a mobject every frame.

animate

Used to animate the application of any method of self.

animation_overrides

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

height

The height of the mobject.

n_points_per_curve

sheen_factor

stroke_color

width

The width of the mobject.

_abc_impl = <_abc._abc_data object>
_bezier_t_values: npt.NDArray[float]
_original__init__(a_mob, b_mob, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), rest_length=1.0, stiffness=100.0, damping=10.0, mob_a_appearance=Dot, mob_b_appearance=Dot, connect_line_class=<class 'manim_pymunk.custom_mobjects.v_spring.VSpring'>, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • a_mob (Mobject)

  • b_mob (Mobject)

  • anchor_a_local (list[float, float, float])

  • anchor_b_local (list[float, float, float])

  • rest_length (float)

  • stiffness (float)

  • damping (float)

  • mob_a_appearance (Mobject)

  • mob_b_appearance (Mobject)

  • connect_line_class (Line | None)

  • connect_line_config (dict)

animation_overrides = {}
background_image: Image | str | None
background_stroke_color: ManimColor
background_stroke_opacity: float
background_stroke_width: float
cap_style: CapStyleType
close_new_points: bool
conn_line: VMobject | None
constraint: DampedSpring | None
install(space)[source]

Verify the validity of constraint parameters.

Parameters:

space (Space)

joint_type: LineJointType
make_smooth_after_applying_functions: bool
mob_updater(mob, dt)[source]

Visual control updater

n_points_per_cubic_curve: int
pre_function_handle_to_anchor_scale_factor: float
shade_in_3d: bool
submobjects: list[VMobject]
tolerance_for_point_equality: float
Parameters:
  • a_mob (Mobject)

  • b_mob (Mobject)

  • anchor_a_local (list[float, float, float])

  • anchor_b_local (list[float, float, float])

  • rest_length (float)

  • stiffness (float)

  • damping (float)

  • mob_a_appearance (Mobject)

  • mob_b_appearance (Mobject)

  • connect_line_class (Line | None)

  • connect_line_config (dict)