mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 20:43:56 +08:00
Update VShowPassingFlash for new path mode
This commit is contained in:
@ -205,25 +205,26 @@ class VShowPassingFlash(Animation):
|
|||||||
self.time_width = time_width
|
self.time_width = time_width
|
||||||
self.taper_width = taper_width
|
self.taper_width = taper_width
|
||||||
super().__init__(vmobject, remover=remover, **kwargs)
|
super().__init__(vmobject, remover=remover, **kwargs)
|
||||||
|
self.mobject = vmobject
|
||||||
|
|
||||||
def begin(self) -> None:
|
def taper_kernel(self, x):
|
||||||
self.mobject.align_stroke_width_data_to_points()
|
|
||||||
# Compute an array of stroke widths for each submobject
|
|
||||||
# which tapers out at either end
|
|
||||||
self.submob_to_anchor_widths = dict()
|
|
||||||
for sm in self.mobject.get_family():
|
|
||||||
original_widths = sm.get_stroke_widths()
|
|
||||||
anchor_widths = np.array([*original_widths[0::3], original_widths[-1]])
|
|
||||||
|
|
||||||
def taper_kernel(x):
|
|
||||||
if x < self.taper_width:
|
if x < self.taper_width:
|
||||||
return x
|
return x
|
||||||
elif x > 1 - self.taper_width:
|
elif x > 1 - self.taper_width:
|
||||||
return 1.0 - x
|
return 1.0 - x
|
||||||
return 1.0
|
return 1.0
|
||||||
|
|
||||||
taper_array = list(map(taper_kernel, np.linspace(0, 1, len(anchor_widths))))
|
def begin(self) -> None:
|
||||||
self.submob_to_anchor_widths[hash(sm)] = anchor_widths * taper_array
|
self.mobject.align_stroke_width_data_to_points()
|
||||||
|
# Compute an array of stroke widths for each submobject
|
||||||
|
# which tapers out at either end
|
||||||
|
self.submob_to_widths = dict()
|
||||||
|
for sm in self.mobject.get_family():
|
||||||
|
widths = sm.get_stroke_widths()
|
||||||
|
self.submob_to_widths[hash(sm)] = np.array([
|
||||||
|
width * self.taper_kernel(x)
|
||||||
|
for width, x in zip(widths, np.linspace(0, 1, len(widths)))
|
||||||
|
])
|
||||||
super().begin()
|
super().begin()
|
||||||
|
|
||||||
def interpolate_submobject(
|
def interpolate_submobject(
|
||||||
@ -232,26 +233,21 @@ class VShowPassingFlash(Animation):
|
|||||||
starting_sumobject: None,
|
starting_sumobject: None,
|
||||||
alpha: float
|
alpha: float
|
||||||
) -> None:
|
) -> None:
|
||||||
anchor_widths = self.submob_to_anchor_widths[hash(submobject)]
|
widths = self.submob_to_widths[hash(submobject)]
|
||||||
|
|
||||||
# Create a gaussian such that 3 sigmas out on either side
|
# Create a gaussian such that 3 sigmas out on either side
|
||||||
# will equals time_width
|
# will equals time_width
|
||||||
tw = self.time_width
|
tw = self.time_width
|
||||||
sigma = tw / 6
|
sigma = tw / 6
|
||||||
mu = interpolate(-tw / 2, 1 + tw / 2, alpha)
|
mu = interpolate(-tw / 2, 1 + tw / 2, alpha)
|
||||||
|
|
||||||
def gauss_kernel(x):
|
xs = np.linspace(0, 1, len(widths))
|
||||||
if abs(x - mu) > 3 * sigma:
|
zs = (xs - mu) / sigma
|
||||||
return 0
|
gaussian = np.exp(-0.5 * zs * zs)
|
||||||
z = (x - mu) / sigma
|
gaussian[abs(xs - mu) > 3 * sigma] = 0
|
||||||
return math.exp(-0.5 * z * z)
|
|
||||||
|
submobject.set_stroke(width=widths * gaussian)
|
||||||
|
|
||||||
kernel_array = list(map(gauss_kernel, np.linspace(0, 1, len(anchor_widths))))
|
|
||||||
scaled_widths = anchor_widths * kernel_array
|
|
||||||
new_widths = np.zeros(submobject.get_num_points())
|
|
||||||
new_widths[0::3] = scaled_widths[:-1]
|
|
||||||
new_widths[2::3] = scaled_widths[1:]
|
|
||||||
new_widths[1::3] = (new_widths[0::3] + new_widths[2::3]) / 2
|
|
||||||
submobject.set_stroke(width=new_widths)
|
|
||||||
|
|
||||||
def finish(self) -> None:
|
def finish(self) -> None:
|
||||||
super().finish()
|
super().finish()
|
||||||
|
Reference in New Issue
Block a user