Skip to content

Commit

Permalink
Adding audio functionality to phaseflow animation
Browse files Browse the repository at this point in the history
  • Loading branch information
JayNibhanupudy committed Oct 4, 2024
1 parent 1dcb812 commit c188d68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions manim/animation/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import pygame

__all__ = [
"Homotopy",
"SmoothedVectorizedHomotopy",
Expand Down Expand Up @@ -112,17 +114,24 @@ def __init__(
virtual_time: float = 1,
suspend_mobject_updating: bool = False,
rate_func: Callable[[float], float] = linear,
sound_file: str = "path/to/your/sound.wav", # Addition
**kwargs,
) -> None:
self.virtual_time = virtual_time
self.function = function
self.sound_file = sound_file # Addition
super().__init__(
mobject,
suspend_mobject_updating=suspend_mobject_updating,
rate_func=rate_func,
**kwargs,
)

def begin(self) -> None: # Addition
super().begin()
# Play sound at the start of the animation
pygame.mixer.Sound(self.sound_file).play()

def interpolate_mobject(self, alpha: float) -> None:
if hasattr(self, "last_alpha"):
dt = self.virtual_time * (
Expand Down

0 comments on commit c188d68

Please sign in to comment.