Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add automatic positioning for live streams

Mehmet Mert Yıldıran846a8249472b
diff --git a/animation/creation.py b/animation/creation.py
index 2c82c2328..f35e8db5a 100644
--- a/animation/creation.py
+++ b/animation/creation.py
@@ -15,6 +15,8 @@ from utils.paths import counterclockwise_path
from utils.rate_functions import double_smooth
from utils.rate_functions import smooth
+import position
+
# Drawing
@@ -98,6 +100,15 @@ class Write(DrawBorderThenFill):
mobject = TextMobject(mob_or_text)
else:
mobject = mob_or_text
+
+ if IS_LIVE_STREAMING:
+ print(position.current)
+ mobject.shift(position.current)
+ position.current = position.current + 2 * DOWN
+ if position.current[1] < -3:
+ position.current[1] = 3
+ position.current = position.current + 3 * RIGHT
+
if "run_time" not in kwargs:
self.establish_run_time(mobject)
if "lag_factor" not in kwargs:
diff --git a/position.py b/position.py
new file mode 100644
index 000000000..fd5dcb2c2
--- /dev/null
+++ b/position.py
@@ -0,0 +1,3 @@
+from constants import *
+
+current = 5 * LEFT + 3 * UP
diff --git a/scene/scene.py b/scene/scene.py
index 2e24319ae..71eceea0f 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -29,6 +29,9 @@ from utils.output_directory_getters import get_image_output_directory
from container.container import Container
+import position
+from mobject.svg.tex_mobject import TextMobject
+from animation.creation import Write
class Scene(Container):
CONFIG = {
@@ -343,6 +346,10 @@ class Scene(Container):
self.mobjects = []
self.foreground_mobjects = []
self.continual_animation = []
+
+ if IS_LIVE_STREAMING:
+ position.current = 5 * LEFT + 3 * UP
+ print(position.current)
return self
def get_mobjects(self):
@@ -512,7 +519,7 @@ class Scene(Container):
n_frames = 1
frame = self.get_frame()
self.add_frames(*[frame] * n_frames)
- sleep(self.frame_duration * 999/1000)
+ sleep(self.frame_duration * 99/100)
def clean_up_animations(self, *animations):
for animation in animations:
@@ -631,6 +638,7 @@ class Scene(Container):
'-pix_fmt', 'rgba',
'-r', str(fps), # frames per second
'-i', '-', # The imput comes from a pipe
+ '-c:v', 'h264_nvenc',
'-an', # Tells FFMPEG not to expect any audio
'-loglevel', 'error',
]
@@ -667,6 +675,10 @@ class Scene(Container):
else:
os.rename(*self.args_to_rename_file)
+ def tex(self, latex):
+ eq = TextMobject(latex)
+ self.play(Write(eq))
+
class EndSceneEarlyException(Exception):
pass