A community-maintained Python framework for creating mathematical animations.
Add a stream lock and an idle state for stream to provide continuous frame flow
Mehmet Mert Yildirana229bdc9c939
diff --git a/scene/scene.py b/scene/scene.pyindex 95a863eaa..f427d1b9b 100644--- a/scene/scene.py+++ b/scene/scene.py@@ -7,6 +7,11 @@ import randomimport shutilimport subprocess as spimport warnings+from time import sleep+try:+ import thread # Low-level threading API (Python 2.7)+except ImportError:+ import _thread as thread # Low-level threading API (Python 3.x)from tqdm import tqdm as ProgressDisplay@@ -58,6 +63,7 @@ class Scene(Container):self.frame_num = 0self.current_scene_time = 0self.original_skipping_status = self.skip_animations+ self.stream_lock = Falseif self.name is None:self.name = self.__class__.__name__if self.random_seed is not None:@@ -455,6 +461,8 @@ class Scene(Container):raise EndSceneEarlyException()def play(self, *args, **kwargs):+ if IS_LIVE_STREAMING:+ self.stream_lock = Falseif len(args) == 0:warnings.warn("Called Scene.play with no animations")return@@ -491,8 +499,21 @@ class Scene(Container):else:self.continual_update(0)self.num_plays += 1++ if IS_LIVE_STREAMING:+ self.stream_lock = True+ thread.start_new_thread(self.idle_stream, ())+return self+ def idle_stream(self):+ while(self.stream_lock):+ self.update_frame()+ n_frames = 1+ frame = self.get_frame()+ self.add_frames(*[frame] * n_frames)+ sleep(self.frame_duration * 999/1000)+def clean_up_animations(self, *animations):for animation in animations:animation.clean_up(self)diff --git a/stream_starter.py b/stream_starter.pynew file mode 100644index 000000000..17794c4c8--- /dev/null+++ b/stream_starter.py@@ -0,0 +1,13 @@+from big_ol_pile_of_manim_imports import *+import subprocess+from time import sleep+from manim import Manim++if not IS_STREAMING_TO_TWITCH:+ FNULL = open(os.devnull, 'w')+ subprocess.Popen([STREAMING_CLIENT, STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT + '?listen'], stdout=FNULL, stderr=FNULL)+ sleep(3)++manim = Manim()++print("YOUR STREAM IS READY!")diff --git a/test1.py b/test1.pydeleted file mode 100644index 70d65e882..000000000--- a/test1.py+++ /dev/null@@ -1,28 +0,0 @@-from big_ol_pile_of_manim_imports import *-from manim import Manim---manim = Manim()--circle = Circle()-square = Square()-line = Line(np.array([3,0,0]),np.array([5,0,0]))-triangle = Polygon(np.array([0,0,0]),np.array([1,1,0]),np.array([1,-1,0]))--manim.wait(3)-manim.add(line)-manim.wait(3)-manim.play(ShowCreation(circle))-manim.wait(3)-manim.play(FadeOut(circle))-manim.wait(3)-manim.play(GrowFromCenter(square))-manim.wait(3)-manim.play(Transform(square,triangle))-manim.wait(10)--manim.close_movie_pipe()--# ffplay tcp://127.0.0.1:2000?listen-# for listening the stream-# start mplayer before running this script