def get_graph( self, func, color=None, x_min=None, x_max=None, **kwargs ): if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, **kwargs ) graph.underlying_function = func return graph
def make_path(func, x_min=0, x_max=1, y_max=None, y_infinity=10, color="#ffffff", **kwargs): def parametric(alpha=1, override_x=None): if override_x == None: x = interpolate(x_min, x_max, alpha) else: x = override_x y = func(x) if not np.isfinite(y) or (y_max and y >= y_max): y = y_infinity return (x, y, 0) path = ParametricFunction(parametric, color=color, **kwargs) path.underlying_function = func path.para_func = parametric path.x_min = x_min path.x_max = x_max return path
def add_curve(self, func, color=None, x_min=None, x_max=None, parameters=None, **kwargs): if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha, **parameters): x = interpolate(x_min, x_max, alpha) y = func(x, **parameters) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) curve = ParametricFunction(parameterized_function, parameters=parameters, color=color, **kwargs) curve.underlying_function = func if hasattr(self, "curves") is False: self.curves = VGroup() self.curves.add(curve) self.add(self.curves) return curve
def swap_variables_animation(v1_ind, v2_ind, text_mobject: TextMobject): v1 = text_mobject.submobjects[v1_ind] v2 = text_mobject.submobjects[v2_ind] v1_text = text_mobject.submobjects[v1_ind].get_tex_string() v2_text = text_mobject.submobjects[v2_ind].get_tex_string() new_text = [obj.get_tex_string() for obj in text_mobject.submobjects] new_text[v1_ind] = v2_text new_text[v2_ind] = v1_text new_text_mobject = TextMobject(*new_text, arg_separator='') new_text_mobject.shift(text_mobject.get_left() - new_text_mobject.get_left()) new_v1_center = new_text_mobject.submobjects[v2_ind].get_center() new_v2_center = new_text_mobject.submobjects[v1_ind].get_center() v1_movement = MoveAlongPath(v1, ParametricFunction( lambda t: clockwise_path()(v1.get_center(), new_v1_center, t))) v2_movement = MoveAlongPath(v2, ParametricFunction( lambda t: clockwise_path()(v2.get_center(), new_v2_center, t))) return v1_movement, v2_movement
def get_parametric_curve(self, function, **kwargs): dim = self.dimension graph = ParametricFunction( lambda t: self.coords_to_point( *function(t)[:dim] ), **kwargs ) graph.underlying_function = function return graph
def get_graph(self, function, **kwargs): x_min = kwargs.pop("x_min", self.x_min) x_max = kwargs.pop("x_max", self.x_max) graph = ParametricFunction( lambda t: self.coords_to_point(t, function(t)), t_min=x_min, t_max=x_max, **kwargs) graph.underlying_function = function return graph
def get_graph( self, func, color=None, x_min=None, x_max=None, **kwargs ): """ This method gets a curve to plot on the graph. Parameters ---------- func : function The function to plot. It's return value should be the y-coordinate for a given x-coordinate color : str The string of the RGB color of the curve. in Hexadecimal representation. x_min : (Union[int,float]) The lower x_value from which to plot the curve. x_max : (Union[int,float]) The higher x_value until which to plot the curve. **kwargs: Any valid keyword arguments of ParametricFunction. Return ------ ParametricFunction The Parametric Curve for the function passed. """ if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, **kwargs ) graph.underlying_function = func return graph
def get_graph(self, function, num_graph_points=None, x_min=None, x_max=None, **kwargs): kwargs["fill_opacity"] = kwargs.get("fill_opacity", 0) kwargs["num_anchor_points"] = \ num_graph_points or self.default_num_graph_points x_min = x_min or self.x_min x_max = x_max or self.x_max graph = ParametricFunction( lambda t: self.coords_to_point(t, function(t)), t_min=x_min, t_max=x_max, **kwargs) graph.underlying_function = function return graph
def get_graph( self, func, color=None, x_min=None, x_max=None, ): """ Parameters ---------- func : Function This function must be continuous color : Hexadecimal color Color x_min : float TODO x_max : float TODO """ if color is None: color = next(self.default_graph_colors_cycle) if x_min is None: x_min = self.x_min if x_max is None: x_max = self.x_max def parameterized_function(alpha): x = interpolate(x_min, x_max, alpha) y = func(x) if not np.isfinite(y): y = self.y_max return self.coords_to_point(x, y) graph = ParametricFunction( parameterized_function, color=color, num_anchor_points=self.num_graph_anchor_points, ) graph.underlying_function = func return graph
def get_move_group_animation(group, vector, **kwargs): group_center = group.get_center() animation = MoveAlongPath(group, ParametricFunction( lambda t: t * vector + group_center), **kwargs) return animation
def put_onto_animation(what, center_should): dif_vec = center_should - what.get_center() mid_point = what.get_center() + dif_vec * 0.5 + UP * dif_vec[1] * 2 return MoveAlongPath(what, ParametricFunction(bezier([what.get_center(), mid_point, center_should])))