Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def color_gradient(reference_colors, length_of_output):
if length_of_output == 0:
return reference_colors[0]
rgbs = list(map(color_to_rgb, reference_colors))
alphas = np.linspace(0, (len(rgbs) - 1), length_of_output)
floors = alphas.astype('int')
alphas_mod1 = alphas % 1
# End edge case
alphas_mod1[-1] = 1
floors[-1] = len(rgbs) - 2
return [
rgb_to_color(interpolate(rgbs[i], rgbs[i + 1], alpha))
for i, alpha in zip(floors, alphas_mod1)
]
def set_color_by_gradient(self, *colors):
self.rgbas = np.array(list(map(
color_to_rgba,
color_gradient(colors, len(self.points))
)))
return self
start_rgba, end_rgba = list(map(color_to_rgba, [start_color, end_color]))
for mob in self.family_members_with_points():
num_points = mob.get_num_points()
mob.rgbas = np.array([
interpolate(start_rgba, end_rgba, alpha)
for alpha in np.arange(num_points) / float(num_points)
])
return self
def point_to_number(self, point):
start_point, end_point = self.get_start_and_end()
full_vect = end_point - start_point
unit_vect = normalize(full_vect)
def distance_from_start(p):
return np.dot(p - start_point, unit_vect)
proportion = fdiv(
distance_from_start(point),
distance_from_start(end_point)
)
return interpolate(self.x_min, self.x_max, proportion)
def add_line_to(self, point):
nppcc = self.n_points_per_cubic_curve
self.add_cubic_bezier_curve_to(*[
interpolate(self.get_last_point(), point, a)
for a in np.linspace(0, 1, nppcc)[1:]
])
return self
def update_func(group, alpha):
dx = interpolate(start_dx, target_dx, alpha)
x = interpolate(start_x, target_x, alpha)
kwargs = dict(secant_slope_group.kwargs)
kwargs["dx"] = dx
kwargs["x"] = x
new_group = self.get_secant_slope_group(**kwargs)
group.become(new_group)
return group
def build_animations_with_timings(self):
"""
Creates a list of triplets of the form
(anim, start_time, end_time)
"""
self.anims_with_timings = []
curr_time = 0
for anim in self.animations:
start_time = curr_time
end_time = start_time + anim.get_run_time()
self.anims_with_timings.append(
(anim, start_time, end_time)
)
# Start time of next animation is based on
# the lag_ratio
curr_time = interpolate(
start_time, end_time, self.lag_ratio
)
def interpolate_color(self, mobject1, mobject2, alpha):
attrs = [
"fill_rgbas",
"stroke_rgbas",
"background_stroke_rgbas",
"stroke_width",
"background_stroke_width",
"sheen_direction",
"sheen_factor",
]
for attr in attrs:
setattr(self, attr, interpolate(
getattr(mobject1, attr),
getattr(mobject2, attr),
alpha
))
if alpha == 1.0:
setattr(self, attr, getattr(mobject2, attr))
def get_bounds(self, alpha):
tw = self.time_width
upper = interpolate(0, 1 + tw, alpha)
lower = upper - tw
upper = min(upper, 1)
lower = max(lower, 0)
return (lower, upper)
def func(values):
alphas = inverse_interpolate(
min_value, max_value, np.array(values)
)
alphas = np.clip(alphas, 0, 1)
# if flip_alphas:
# alphas = 1 - alphas
scaled_alphas = alphas * (len(rgbs) - 1)
indices = scaled_alphas.astype(int)
next_indices = np.clip(indices + 1, 0, len(rgbs) - 1)
inter_alphas = scaled_alphas % 1
inter_alphas = inter_alphas.repeat(3).reshape((len(indices), 3))
result = interpolate(rgbs[indices], rgbs[next_indices], inter_alphas)
return result
return func
def set_points_as_corners(self, points):
nppcc = self.n_points_per_cubic_curve
points = np.array(points)
self.set_anchors_and_handles(*[
interpolate(points[:-1], points[1:], a)
for a in np.linspace(0, 1, nppcc)
])
return self