Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Prevent ned to create new cairo ImageSurface with each frame

Grant Sanderson3d5826229bf1
diff --git a/camera/camera.py b/camera/camera.py
index d5775983c..16e687faf 100644
--- a/camera/camera.py
+++ b/camera/camera.py
@@ -280,7 +280,7 @@ class Camera(object):
# Methods associated with svg rendering
- def get_cairo_context(self):
+ def create_new_cairo_context(self):
# TODO, make sure this isn't run too much
pw = self.get_pixel_width()
ph = self.get_pixel_height()
@@ -300,6 +300,14 @@ class Camera(object):
))
return ctx
+ def get_cairo_context(self):
+ if not hasattr(self, "cairo_context"):
+ ctx = self.create_new_cairo_context()
+ self.cairo_context = ctx
+ else:
+ ctx = self.cairo_context
+ return ctx
+
def display_multiple_vectorized_mobjects(self, vmobjects):
if len(vmobjects) == 0:
return
@@ -344,7 +352,7 @@ class Camera(object):
return self
def set_cairo_context_color(self, ctx, rgbas, vmobject):
- if len(rgbas) == 0:
+ if len(rgbas) == 1:
# Use reversed rgb because cairo surface is
# encodes it in reverse order
ctx.set_source_rgba(