Skip to content

Commit

Permalink
Performance improvement for Write
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Jan 13, 2021
1 parent 2c27511 commit 8b83c5e
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions manimlib/animation/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class ShowPartial(Animation):
"""
Abstract class for ShowCreation and ShowPassingFlash
"""
CONFIG = {
"should_match_start": False,
}

def begin(self):
super().begin()
if not self.should_match_start:
self.mobject.lock_matching_data(self.mobject, self.starting_mobject)

def interpolate_submobject(self, submob, start_submob, alpha):
submob.pointwise_become_partial(
Expand All @@ -38,7 +46,8 @@ def get_bounds(self, alpha):
class Uncreate(ShowCreation):
CONFIG = {
"rate_func": lambda t: smooth(1 - t),
"remover": True
"remover": True,
"should_match_start": True,
}


Expand All @@ -53,18 +62,18 @@ class DrawBorderThenFill(Animation):
}

def __init__(self, vmobject, **kwargs):
self.check_validity_of_input(vmobject)
assert(isinstance(vmobject, VMobject))
self.sm_to_index = dict([
(hash(sm), 0)
for sm in vmobject.get_family()
])
super().__init__(vmobject, **kwargs)

def check_validity_of_input(self, vmobject):
if not isinstance(vmobject, VMobject):
raise Exception(
"DrawBorderThenFill only works for VMobjects"
)

def begin(self):
self.outline = self.get_outline()
super().begin()
self.mobject.match_style(self.outline)
self.mobject.lock_matching_data(self.mobject, self.outline)

def get_outline(self):
outline = self.mobject.copy()
Expand All @@ -88,11 +97,17 @@ def get_all_mobjects(self):

def interpolate_submobject(self, submob, start, outline, alpha):
index, subalpha = integer_interpolate(0, 2, alpha)

if index == 1 and self.sm_to_index[hash(submob)] == 0:
# First time crossing over
submob.set_data(outline.data)
submob.unlock_data()
submob.lock_matching_data(submob, start)
self.sm_to_index[hash(submob)] = 1

if index == 0:
submob.pointwise_become_partial(outline, 0, subalpha)
submob.match_style(outline)
else:
submob.pointwise_become_partial(outline, 0, 1)
submob.interpolate(outline, start, subalpha)


Expand Down

0 comments on commit 8b83c5e

Please sign in to comment.