Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding audio functionality to phaseflow animation #3942

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading