|
12 | 12 |
|
13 | 13 | from manim.mobject.opengl.opengl_mobject import OpenGLMobject |
14 | 14 |
|
15 | | -from .. import logger |
| 15 | +from .. import config, logger |
16 | 16 | from ..mobject import mobject |
17 | 17 | from ..mobject.mobject import Mobject |
18 | 18 | from ..mobject.opengl import opengl_mobject |
@@ -209,6 +209,7 @@ def begin(self) -> None: |
209 | 209 | method. |
210 | 210 |
|
211 | 211 | """ |
| 212 | + self.run_time = validate_run_time(self.run_time, str(self)) |
212 | 213 | self.starting_mobject = self.create_starting_mobject() |
213 | 214 | if self.suspend_mobject_updating: |
214 | 215 | # All calls to self.mobject's internal updaters |
@@ -551,6 +552,33 @@ def prepare_animation( |
551 | 552 | raise TypeError(f"Object {anim} cannot be converted to an animation") from None |
552 | 553 |
|
553 | 554 |
|
| 555 | +def validate_run_time( |
| 556 | + run_time: float, caller_name: str, parameter_name: str = "run_time" |
| 557 | +) -> float: |
| 558 | + if run_time <= 0: |
| 559 | + raise ValueError( |
| 560 | + f"{caller_name} has a {parameter_name} of {run_time:g} <= 0 " |
| 561 | + f"seconds which Manim cannot render. Please set the " |
| 562 | + f"{parameter_name} to a positive number." |
| 563 | + ) |
| 564 | + |
| 565 | + # config.frame_rate holds the number of frames per second |
| 566 | + fps = config.frame_rate |
| 567 | + seconds_per_frame = 1 / fps |
| 568 | + if run_time < seconds_per_frame: |
| 569 | + logger.warning( |
| 570 | + f"The original {parameter_name} of {caller_name}, {run_time:g} " |
| 571 | + f"seconds, is too short for the current frame rate of {fps:g} " |
| 572 | + f"FPS. Rendering with the shortest possible {parameter_name} of " |
| 573 | + f"{seconds_per_frame:g} seconds instead." |
| 574 | + ) |
| 575 | + new_run_time = seconds_per_frame |
| 576 | + else: |
| 577 | + new_run_time = run_time |
| 578 | + |
| 579 | + return new_run_time |
| 580 | + |
| 581 | + |
554 | 582 | class Wait(Animation): |
555 | 583 | """A "no operation" animation. |
556 | 584 |
|
@@ -590,7 +618,7 @@ def __init__( |
590 | 618 | super().__init__(None, run_time=run_time, rate_func=rate_func, **kwargs) |
591 | 619 |
|
592 | 620 | def begin(self) -> None: |
593 | | - pass |
| 621 | + self.run_time = validate_run_time(self.run_time, str(self)) |
594 | 622 |
|
595 | 623 | def finish(self) -> None: |
596 | 624 | pass |
|
0 commit comments