def construct(self): number_line = NumberLine(x_min=-2, x_max=2) text_1 = TextMobject("Theorem of") \ .next_to(number_line, DOWN) text_2 = TextMobject("Beethoven") \ .next_to(number_line, DOWN) dashed_line = DashedLine( number_line.get_left(), number_line.get_right(), color=YELLOW, ).set_stroke(width=11) self.add(number_line, text_1) self.play( LaggedStart(*[ ShowCreationThenDestruction(dashed_segment) for dashed_segment in dashed_line ], run_time=5), AnimationGroup(Animation(Mobject(), run_time=2.1), ReplacementTransform(text_1, text_2), lag_ratio=1)) 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) 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 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 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) text = TextMobject("Text") \ .next_to(number_line, DOWN) dashed_line = DashedLine( number_line.get_left(), number_line.get_right(), color=YELLOW, ).set_stroke(width=11) self.add(number_line) self.wait(0.3) self.play( LaggedStart(*[ ShowCreationThenDestruction(dashed_segment) for dashed_segment in dashed_line ], run_time=5), AnimationGroup(Animation(Mobject(), run_time=2.1), Write(text), lag_ratio=1)) 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()