Changes to AnimatedBoundary

This commit is contained in:
Grant Sanderson 2019-04-02 17:42:50 -07:00
parent 065605f6c6
commit 043e3986f6

View file

@ -8,6 +8,9 @@ class AnimatedBoundary(VGroup):
"colors": [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN], "colors": [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
"max_stroke_width": 3, "max_stroke_width": 3,
"cycle_rate": 0.5, "cycle_rate": 0.5,
"back_and_forth": True,
"draw_rate_func": smooth,
"fade_rate_func": smooth,
} }
def __init__(self, vmobject, **kwargs): def __init__(self, vmobject, **kwargs):
@ -37,12 +40,14 @@ class AnimatedBoundary(VGroup):
vmobject = self.vmobject vmobject = self.vmobject
index = int(time % len(colors)) index = int(time % len(colors))
alpha = smooth(time % 1) alpha = time % 1
draw_alpha = self.draw_rate_func(alpha)
fade_alpha = self.fade_rate_func(alpha)
if int(time) % 2 == 0: if self.back_and_forth and int(time) % 1 == 0:
bounds = (0, alpha) bounds = (1 - draw_alpha, 1)
else: else:
bounds = (1 - alpha, 1) bounds = (0, draw_alpha)
self.full_family_become_partial(growing, vmobject, *bounds) self.full_family_become_partial(growing, vmobject, *bounds)
growing.set_stroke(colors[index], width=msw) growing.set_stroke(colors[index], width=msw)
@ -50,7 +55,7 @@ class AnimatedBoundary(VGroup):
self.full_family_become_partial(fading, vmobject, 0, 1) self.full_family_become_partial(fading, vmobject, 0, 1)
fading.set_stroke( fading.set_stroke(
color=colors[index - 1], color=colors[index - 1],
width=(1 - alpha) * msw width=(1 - fade_alpha) * msw
) )
self.total_time += dt self.total_time += dt