def generate_symbol(self): symbol = RegularPolygon( n = 3, stroke_width = 0, fill_color = self.color, fill_opacity = 1, ) symbol.set_height(self.inner_radius) return symbol
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs): triangle = RegularPolygon(n=3, start_angle=np.pi / 2) triangle.set_height(MED_SMALL_BUFF) triangle.move_to(self.coords_to_point(x_val, 0), UP) triangle.set_fill(color, 1) triangle.set_stroke(width=0) if label is None: T_label = TexMobject(self.variable_point_label, fill_color=color) else: T_label = TexMobject(label, fill_color=color) T_label.next_to(triangle, DOWN) v_line = self.get_vertical_line_to_graph(x_val, self.v_graph, color=YELLOW) if animated: self.play(DrawBorderThenFill(triangle), ShowCreation(v_line), Write(T_label, run_time=1), **kwargs) if np.all(side == LEFT): self.left_T_label_group = VGroup(T_label, triangle) self.left_v_line = v_line self.add(self.left_T_label_group, self.left_v_line) elif np.all(side == RIGHT): self.right_T_label_group = VGroup(T_label, triangle) self.right_v_line = v_line self.add(self.right_T_label_group, self.right_v_line)
def construct(self): number_line = NumberLine(x_min=-1, x_max=1) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) decimal = DecimalNumber( 0, num_decimal_places=3, include_sign=True, unit="\\rm cm", # Change this with None ) decimal.add_updater(lambda d: d.next_to(triangle, UP * 0.1)) decimal.add_updater(lambda d: d.set_value(triangle.get_center()[0])) # You can get the value of decimal with: .get_value() self.add(number_line, triangle, decimal) self.play( triangle.shift, RIGHT * 2, rate_func=there_and_back, # Change this with: linear,smooth run_time=5) self.wait()
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs): """ This method adds to the Scene: -- a Vertical line from the x-axis to the corresponding point on the graph/curve. -- a small vertical Triangle whose top point lies on the base of the vertical line -- a TexMobject to be a label for the Line and Triangle, at the bottom of the Triangle. The scene needs to have the graph have the identifier/variable name self.v_graph. Parameters ---------- x_val (Union[float, int]) The x value at which the secant enters, and intersects the graph for the first time. side (np.ndarray()) label (str) The label to give the vertline and triangle color (str) The hex color of the label. animated (bool=False) Whether or not to animate the addition of the T_label **kwargs Any valid keyword argument of a self.play call. """ triangle = RegularPolygon(n=3, start_angle=np.pi / 2) triangle.set_height(MED_SMALL_BUFF) triangle.move_to(self.coords_to_point(x_val, 0), UP) triangle.set_fill(color, 1) triangle.set_stroke(width=0) if label is None: T_label = TexMobject(self.variable_point_label, fill_color=color) else: T_label = TexMobject(label, fill_color=color) T_label.next_to(triangle, DOWN) v_line = self.get_vertical_line_to_graph( x_val, self.v_graph, color=YELLOW ) if animated: self.play( DrawBorderThenFill(triangle), ShowCreation(v_line), Write(T_label, run_time=1), **kwargs ) if np.all(side == LEFT): self.left_T_label_group = VGroup(T_label, triangle) self.left_v_line = v_line self.add(self.left_T_label_group, self.left_v_line) elif np.all(side == RIGHT): self.right_T_label_group = VGroup(T_label, triangle) self.right_v_line = v_line self.add(self.right_T_label_group, self.right_v_line)
def generate_points(self): self.points = [] inner_tri = RegularPolygon(n = 3, start_angle = np.pi/2) outer_tri = RegularPolygon(n = 3, start_angle = np.pi/2) inner_tri.flip() inner_tri.set_height(self.inner_height, about_point = ORIGIN) outer_tri.set_height(self.outer_height, about_point = ORIGIN) self.points = outer_tri.points self.add_subpath(inner_tri.points)
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs): triangle = RegularPolygon(n=3, start_angle=np.pi / 2) triangle.set_height(MED_SMALL_BUFF) triangle.move_to(self.coords_to_point(x_val, 0), UP) triangle.set_fill(color, 1) triangle.set_stroke(width=0) if label is None: T_label = TexMobject(self.variable_point_label, fill_color=color) else: T_label = TexMobject(label, fill_color=color) T_label.next_to(triangle, DOWN) v_line = self.get_vertical_line_to_graph( x_val, self.v_graph, color=YELLOW ) if animated: self.play( DrawBorderThenFill(triangle), ShowCreation(v_line), Write(T_label, run_time=1), **kwargs ) if np.all(side == LEFT): self.left_T_label_group = VGroup(T_label, triangle) self.left_v_line = v_line self.add(self.left_T_label_group, self.left_v_line) elif np.all(side == RIGHT): self.right_T_label_group = VGroup(T_label, triangle) self.right_v_line = v_line self.add(self.right_T_label_group, self.right_v_line)
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) numbers = VGroup( *[TextMobject("%s" % i) \ .next_to(number_line.get_tick(i - 2), DOWN) for i in range(1, 5)] ) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), *[ AnimationGroup(Animation(Mobject(), run_time=i + 1), Write(numbers[i]), lag_ratio=1) for i in range(4) ], ) self.wait()
def generate_symbol(self): symbol = VGroup(*[ RegularPolygon( n=3, stroke_width=0, fill_color=self.color, fill_opacity=1) for i in range(2) ]) symbol.arrange_submobjects(RIGHT, buff=0) symbol.set_height(self.inner_radius * 0.7) return symbol
def construct(self): number_line = NumberLine(x_min=-1, x_max=1) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) def update_t(triangle, dt): triangle.shift(RIGHT * dt) self.add(number_line, triangle) self.wait(0.3) triangle.shift(LEFT) triangle.add_updater(update_t) # The animation begins self.wait(2) triangle.clear_updaters() self.wait()
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) text_1 = TextMobject("1") \ .next_to(number_line.get_tick(-1), DOWN) text_2 = TextMobject("2") \ .next_to(number_line.get_tick(0), DOWN) text_3 = TextMobject("3") \ .next_to(number_line.get_tick(1), DOWN) text_4 = TextMobject("4") \ .next_to(number_line.get_tick(2), DOWN) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), AnimationGroup(Animation(Mobject(), run_time=1), Write(text_1), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=2), Write(text_2), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=3), Write(text_3), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=4), Write(text_4), lag_ratio=1)) self.wait()
def get_seed_shape(self): return RegularPolygon(n=6)
def get_seed_shape(self): return RegularPolygon(n=5, start_angle=np.pi / 2)
def __init__(self, screen01=[], screen02=[], screen03=[], lag_ratio=1, **kwargs): mobjs_1, mobjs_1_scale, mobjs_1_interval, mobjs_1_rate_func, \ title_1, title_1_color, title_1_scale, title_1_position, title_1_shadow, \ title_1_indicate_scale_factor, title_1_extra = screen01 + \ ["", 2, 0.5, linear, "", "#0808B8", 2, [DOWN], [2, slice(0, 3, 2)], 1.2, ""][len(screen01):] mobjs_2, mobjs_2_scale, mobjs_2_interval, mobjs_2_rate_func, \ title_2, title_2_color, title_2_scale, title_2_position, title_2_shadow, \ title_2_indicate_scale_factor, title_2_extra = screen02 + \ ["", 2, 0.5, linear, "", "#0808B8", 1.2, [DOWN], [2, slice(1, 4, 2)], "", [slice(1, 2), WHITE, [-2.5, 0, 0]]][len(screen02):] [title, subtitle, filename, reference, warning, mobjes_3_run_time] =\ screen03 + [[], [], [], [], [], 3][len(screen03):] [title, title_color, title_scale, title_position] = title + \ ["", WHITE, 1, [UP]][len(title):] [subtitle, subtitle_color, subtitle_scale, subtitle_position] = subtitle + \ ["", WHITE, 1, [0, 0, 0]][len(subtitle):] [filename, filename_color, filename_scale, filename_position] = filename + \ ["", WHITE, 1, [0, -2.9, 0]][len(filename):] [reference, reference_color, reference_scale, reference_position] = reference + \ ["", YELLOW, 1, [0, -3.3, 0]][len(reference):] [warning, warning_color, warning_scale, warning_position] = warning + \ ["", YELLOW, 1, [0, -3.7, 0] ][len(warning):] startscreens = AGroup() if mobjs_1 != None: if mobjs_1 == "": try: mobjs_1 = ImageMobjectGroup( np.char.mod('%01d', range(0, 10)), "sidewayoutput\\sidewayoutput2020yt") except: mobjs_1 = ImageMobjectGroup( np.char.mod('%01d', range(9, -1, -1)), "001\\") if title_1 == "": title_1 = PoweredBy title_1 = MobjectOrChars(title_1) title_1.set_color(title_1_color).scale( title_1_scale).align_on_border( *title_1_position).add_shadow_mobjects( title_1_shadow[0], title_1[title_1_shadow[1]]) if title_1_extra != "": title_1[title_1_extra[0]].set_color(title_1_extra[1]).shift( title_1_extra[2]) if title_1_indicate_scale_factor == "": title_width = mobjs_1.get_width() title_1_indicate_scale_factor = (title_width - 0.5) / title_width startscreens.add( ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut( mobjs_1.scale(mobjs_1_scale), title_1, indicate_scale_factor=title_1_indicate_scale_factor, show_rate_func=mobjs_1_rate_func, run_time=mobjs_1_interval * (len(mobjs_1)), **kwargs)) if mobjs_2 != None: if mobjs_2 == "": strs = TextMobject(r"\textspA{%s}" % Project) mobjs_2 = Group( Circle(fill_opacity=0.75), RegularPolygon(fill_opacity=0.75), Triangle(color=GREEN, fill_opacity=0.75), Square(fill_opacity=0.75), strs.set_color("#FFFFFF"), strs.copy().set_color("#F8F8F8").scale(1.3), strs.copy().set_color("#F8F8B8").scale(1.6), strs.copy().set_color("#B8B8B8").scale(1.6), strs.copy().set_color("#8888B8").scale(1.6), strs.copy().set_color("#6868B8").scale(1.6), strs.copy().set_color("#4848B8").scale(1.6), strs.copy().set_color("#2828B8").scale(1.6), strs.copy().set_color("#0808B8").scale(1.6), ) if title_2 == "": title_2 = (r"{\tiny{\emph{Powered by}:}}\\ ", *PoweredBy) title_2 = MobjectOrChars(title_2) title_2.set_color(title_2_color).scale( title_2_scale).align_on_border( *title_2_position).add_shadow_mobjects( title_2_shadow[0], title_2[title_2_shadow[1]]) if title_2_extra != "": title_2[title_2_extra[0]].set_color(title_2_extra[1]).shift( title_2_extra[2]) if title_2_indicate_scale_factor == "": title_width = mobjs_2.get_width() title_2_indicate_scale_factor = (title_width - 0.5) / title_width startscreens.add( ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut( mobjs_2.scale(mobjs_2_scale), title_2, indicate_scale_factor=title_2_indicate_scale_factor, show_rate_func=mobjs_2_rate_func, run_time=mobjs_2_interval * (len(mobjs_2)), **kwargs)) if title != None or subtitle != None: mobjs_3 = [Group(), "", ""] if title != None: txt_title = TextMobject(title).scale(title_scale) if txt_title.get_width() > 14: txt_title.stretch_to_fit_width(14) mobjs_3[1] = txt_title.set_color(title_color).to_edge( *title_position) mobjs_3[0].add(mobjs_3[1]) if subtitle != None: mobjs_3[0].add( TextMobject(subtitle).set_color(subtitle_color).scale( subtitle_scale).shift(subtitle_position)) if filename != None and filename != "": if reference == None or reference == "": filename_position = reference_position mobjs_3[0].add( TextMobject(filename).set_color(filename_color).scale( filename_scale).shift(filename_position)) if reference != None and reference != "": txt_reference = TextMobject(reference).scale(reference_scale) if txt_reference.get_width() > 14: txt_reference.stretch_to_fit_width(14) mobjs_3[0].add( txt_reference.set_color(reference_color).shift( reference_position)) if warning != None and warning != "": txt_warning = TextMobject(warning).scale( warning_scale) # height=0.3 if txt_warning.get_width() > 14: txt_warning.stretch_to_fit_width(14) mobjs_3[2] = txt_warning.set_color(warning_color).shift( warning_position) animations = AGroup() if len(mobjs_3[0]) > 0: animations.add( FadeIn(mobjs_3[0], run_time=0.5, scale_factor=1, color=None)) if len(mobjs_3[1]) > 0: animations.add(GrowFromCenter(Underline(mobjs_3[1]))) if len(mobjs_3[2]) > 0: animations.add( FadeInThenIndicate(mobjs_3[2], run_time=0.5, scale_factor=1.2, color=None)) startscreens.add( FadeoutSuccession(AnimationGroup(*animations, run_time=mobjes_3_run_time), run_time=0.05)) super().__init__(AnimationGroup(*startscreens, lag_ratio=1), **kwargs)