mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Performance improvement for Write
This commit is contained in:
parent
2c27511556
commit
8b83c5e27d
1 changed files with 25 additions and 10 deletions
|
@ -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(
|
||||
|
@ -38,7 +46,8 @@ class ShowCreation(ShowPartial):
|
|||
class Uncreate(ShowCreation):
|
||||
CONFIG = {
|
||||
"rate_func": lambda t: smooth(1 - t),
|
||||
"remover": True
|
||||
"remover": True,
|
||||
"should_match_start": True,
|
||||
}
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -88,11 +97,17 @@ class DrawBorderThenFill(Animation):
|
|||
|
||||
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)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue