def get_vector(self, numerical_vector, **kwargs): return Arrow( self.plane.coords_to_point(0, 0), self.plane.coords_to_point(*numerical_vector[:2]), buff=0, **kwargs )
def add_tip(self): start, end = self.main_line.get_start_and_end() vect = (end - start) / np.linalg.norm(end - start) arrow = Arrow(start, end + MED_SMALL_BUFF * vect, buff=0) tip = arrow.tip tip.set_color(self.color) self.tip = tip self.add(tip)
def generate_points(self): self.arrow_group = VGroup() vertices = self.generate_vertices_from_string(self.walk_string) for k in range(len(vertices) - 1): arrow = Arrow(vertices[k], vertices[k + 1], color=self.get_arrow_color_by_number(k), buff=0) self.arrow_group.add(arrow) self.add(self.arrow_group) self.horizontally_center()
def get_digit_increment_animations(self): result = [] self.number += 1 is_next_digit = self.is_next_digit() if is_next_digit: self.max_place += 1 new_number_mob = self.get_number_mob(self.number) new_number_mob.move_to(self.number_mob, RIGHT) if is_next_digit: self.add_configuration() place = len(new_number_mob.split()) - 1 result.append(FadeIn(self.dot_templates[place])) arrow = Arrow(new_number_mob[place].get_top(), self.dot_templates[place].get_bottom(), color=self.digit_place_colors[place]) self.arrows.add(arrow) result.append(ShowCreation(arrow)) result.append( Transform(self.number_mob, new_number_mob, submobject_mode="lagged_start")) return result
def get_vector(self, coords, **kwargs): point = coords[0] * RIGHT + coords[1] * UP arrow = Arrow(ORIGIN, point, **kwargs) return arrow
def generate_mobject(self, dic, labels_dict): # Create a dictionary with all attributes to create a new Mobject. # Unspecified values will be filled from the current Mobject if it # exists, and with default values if not. if "stroke_width" not in dic: if hasattr(self, "mobject"): dic["stroke_width"] = self.mobject.stroke_width else: print("Attempted to initialize Edge without stroke_width") breakpoint(context=7) if "rectangular_stem_width" not in dic: if hasattr(self, "mobject"): dic["rectangular_stem_width"] = \ self.mobject.rectangular_stem_width else: print("Attempted to initialize Edge without " "rectangular_stem_width") breakpoint(context=7) if "scale_factor" not in dic: if hasattr(self, "mobject"): dic["scale_factor"] = self.mobject.scale_factor else: print("Attempted to initialize Edge without scale_factor") breakpoint(context=7) if "color" not in dic: if hasattr(self, "mobject"): dic["color"] = self.mobject.color if "directed" not in dic: if hasattr(self, "mobject") and self.mobject.directed: dic["directed"] = self.mobject.directed else: dic["directed"] = False if "curved" not in dic: if hasattr(self, "mobject") and self.mobject.curved: dic["curved"] = self.mobject.curved else: dic["curved"] = False # where along the edge the label is placed if "label_location" not in dic: if hasattr(self, "mobject") and self.mobject.label_location: dic["label_location"] = self.mobject.label_location else: dic["label_location"] = 0.5 # which side of the edge on which the label is placed if "label_side" not in dic: if hasattr(self, "mobject") and self.mobject.label_side: dic["label_side"] = self.mobject.label_side else: dic["label_side"] = Side.CLOCKWISE normalized_vec = self.end_node.mobject.get_center() - \ self.start_node.mobject.get_center() normalized_vec = normalized_vec / numpy.linalg.norm(normalized_vec) normal_vec = rotate_vector(normalized_vec, numpy.pi / 2) if dic["directed"]: mob = Arrow(self.start_node.mobject.get_center() + normalized_vec * (self.start_node.mobject.radius - 0.0), self.end_node.mobject.get_center() - normalized_vec * (self.end_node.mobject.radius - 0.0), buff=0, **dic) else: mob = Line( self.start_node.mobject.get_center() + normalized_vec * self.start_node.mobject.radius, self.end_node.mobject.get_center() - normalized_vec * self.end_node.mobject.radius, **dic) if dic["curved"]: start, end = mob.get_start_and_end() midpoint = (start + end) / 2 def f(x): return x - 0.1 * normal_vec * \ (numpy.linalg.norm(start - midpoint) - numpy.linalg.norm(x - midpoint)) mob.shift(-0.05 * normal_vec).apply_function(f) return mob