Skip to content

Commit f473782

Browse files
authored
Video work (#2326)
* Only use -no-pdf for xelatex rendering * Instead of tracking du and dv points on surface, track points off the surface in the normal direction This means that surface shading will not necessarily work well for arbitrary transformations of the surface. But the existing solution was flimsy anyway, and caused annoying issues with singularity points. * Have density of anchor points on arcs depend on arc length * Allow for specifying true normals and orientation of Sphere * Change miter threshold on stroke shader * Add get_start_and_end to DashedLine * Add min_total_width option to DecimalNumber * Have BackgroundRectangle.set_style absorb (and ignore) added configuration Note, this feels suboptimal * Add LineBrace * Update font_size adjustment in Tex * Add scale_factor parameter to BulletedList.fade_all_but * Minor import tweaks * Add play_sound
1 parent be7d93c commit f473782

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

manimlib/mobject/svg/special_tex.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
buff: float = MED_LARGE_BUFF,
2323
aligned_edge: Vect3 = LEFT,
2424
**kwargs
25-
):
25+
):
2626
labelled_content = [R"\item " + item for item in items]
2727
tex_string = "\n".join([
2828
R"\begin{itemize}",
@@ -36,9 +36,12 @@ def __init__(
3636

3737
self.arrange(DOWN, buff=buff, aligned_edge=aligned_edge)
3838

39-
def fade_all_but(self, index: int, opacity: float = 0.25) -> None:
39+
def fade_all_but(self, index: int, opacity: float = 0.25, scale_factor=0.7) -> None:
40+
max_dot_height = max([item[0].get_height() for item in self.submobjects])
4041
for i, part in enumerate(self.submobjects):
42+
trg_dot_height = (1.0 if i == index else scale_factor) * max_dot_height
4143
part.set_fill(opacity=(1.0 if i == index else opacity))
44+
part.scale(trg_dot_height / part[0].get_height(), about_edge=LEFT)
4245

4346

4447
class TexTextFromPresetString(TexText):

manimlib/scene/scene.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
from contextlib import contextmanager
99
from contextlib import ExitStack
1010

11-
from pyglet.window import key as PygletWindowKeys
12-
1311
import numpy as np
1412
from tqdm.auto import tqdm as ProgressDisplay
13+
from pyglet.window import key as PygletWindowKeys
1514

1615
from manimlib.animation.animation import prepare_animation
1716
from manimlib.camera.camera import Camera
@@ -33,6 +32,7 @@
3332
from manimlib.utils.family_ops import extract_mobject_family_members
3433
from manimlib.utils.family_ops import recursive_mobject_remove
3534
from manimlib.utils.iterables import batch_by_property
35+
from manimlib.utils.sounds import play_sound
3636
from manimlib.window import Window
3737

3838
from typing import TYPE_CHECKING

manimlib/utils/sounds.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from __future__ import annotations
22

3+
import subprocess
4+
import threading
5+
import platform
6+
37
from manimlib.utils.directories import get_sound_dir
48
from manimlib.utils.file_ops import find_file
59

@@ -10,3 +14,27 @@ def get_full_sound_file_path(sound_file_name: str) -> str:
1014
directories=[get_sound_dir()],
1115
extensions=[".wav", ".mp3", ""]
1216
)
17+
18+
19+
def play_sound(sound_file):
20+
"""Play a sound file using the system's audio player"""
21+
full_path = get_full_sound_file_path(sound_file)
22+
system = platform.system()
23+
24+
if system == "Windows":
25+
# Windows
26+
subprocess.Popen(
27+
["powershell", "-c", f"(New-Object Media.SoundPlayer '{full_path}').PlaySync()"],
28+
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
29+
)
30+
elif system == "Darwin":
31+
# macOS
32+
subprocess.Popen(
33+
["afplay", full_path],
34+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
35+
)
36+
else:
37+
subprocess.Popen(
38+
["aplay", full_path],
39+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
40+
)

0 commit comments

Comments
 (0)