반응형
UpdateFromFunc class
def update_from_func(self):
dot = Dot().to_edge(LEFT)
label = TextMobject("Hello").next_to(dot,UP)
def update_func(mob):
mob.next_to(dot,UP)
self.play(
dot.to_edge,RIGHT,
UpdateFromFunc(label, update_func),
run_time=5,
)
def update_from_func2(self):
dot = Dot().to_edge(LEFT)
label = TextMobject("Hello").next_to(dot,UP)
def update_func(mob):
mob.next_to(dot, UP)
x = dot.get_center()[0]
new_label = TextMobject(str(round(x,0))).move_to(mob)
mob.become(new_label)
self.play(
dot.to_edge,RIGHT,
UpdateFromFunc(label, update_func),
run_time=5,
)
UpdateFromAlphaFunc class
def watch_alpha_value(self):
dot = Dot(radius=0.5, color=RED).to_edge(LEFT)
dot.save_state()
decimal = DecimalNumber(0).next_to(dot,UP)
def update_number(mob, alpha):
mob.set_value(alpha).next_to(dot, UP)
self.add(dot, decimal)
self.play(dot.to_edge, RIGHT,
UpdateFromAlphaFunc(decimal, update_number),
rate_func=linear,
run_time=3,
)
dot.restore()
self.play(dot.to_edge, RIGHT,
UpdateFromAlphaFunc(decimal, update_number),
rate_func=smooth,
run_time=3,
)
dot.restore()
self.play(dot.to_edge, RIGHT,
UpdateFromAlphaFunc(decimal, update_number),
rate_func=there_and_back,
run_time=5,
)
self.wait()
def update_color_alpha(self):
dot = Dot(radius=0.5, color=RED).to_edge(LEFT)
decimal = DecimalNumber(0).next_to(dot,UP)
def update_number(mob, alpha):
mob.set_value(alpha).next_to(dot, UP)
def update_dot_color(mob, alpha):
mob.set_color(interpolate_color(RED, YELLOW, alpha))
self.add(dot, decimal)
self.play(
dot.to_edge, RIGHT,
UpdateFromAlphaFunc(decimal, update_number),
UpdateFromAlphaFunc(dot, update_dot_color),
rate_func=there_and_back,
run_time=10,
)
self.wait(2)
UpdateFromAlphaFunc -
class SquarePointTest(Scene):
def construct(self):
square = Square()
dot = Dot(color=RED).move_to(square.get_start())
num = DecimalNumber(0).move_to(square)
self.add(square, dot)
self.wait()
def update_dot_pos(mob, alpha):
mob.move_to(square.point_from_proportion(alpha))
def update_num_val(mob, alpha):
num.set_value(alpha)
self.play(
UpdateFromAlphaFunc(dot, update_dot_pos),
UpdateFromAlphaFunc(num, update_num_val),
run_time=5,
rate_func=linear,
)
반응형
'Programming > Manim code' 카테고리의 다른 글
Sine/Cosine curve by rotating the dot around the circle (0) | 2020.09.19 |
---|---|
Sine-curve by rotating dot around the circle (0) | 2020.09.19 |
[48]always_redraw (0) | 2020.05.29 |
[47] add_updater (0) | 2020.05.29 |
[46]Mobject moving/coloring Animation (0) | 2020.05.29 |