반응형
def moving_dot(self):
x_axis = NumberLine(x_min=-5, x_max=5)
dot = Dot(color=RED, radius=0.15).move_to(x_axis.get_left())
number = DecimalNumber(-5, color=RED).next_to(dot, UP)
number.add_updater(lambda m: m.next_to(dot, UP))
number.add_updater(lambda m: m.set_value(dot.get_center()[0]))
self.add(x_axis, dot, number)
self.play(dot.shift, RIGHT * 10, rate_func=there_and_back, run_time=10)
self.wait()
use ValueTracker(1/2)
def digital_colock(self):
vt = ValueTracker(0)
num = DecimalNumber(0, num_decimal_places=3)
num.add_updater(lambda m: m.set_value(vt.get_value()))
self.add(num)
self.play(vt.set_value, 10, rate_func=linear, run_time=10)
self.wait()
use ValueTracker (2/2)
class ValueTrackerTest(Scene):
def construct(self):
img = ImageMobject("assets/img/2.jpg")
img.scale(2.5)
num = DecimalNumber(0)
num.next_to(img, DOWN)
t = Text("Opacity:", stroke_width=0, size=0.4).next_to(num, LEFT)
self.add(img, t, num)
self.wait()
vt = ValueTracker(10)
num.add_updater(lambda m:m.set_value(vt.get_value()/10))
img.add_updater(lambda m: m.set_opacity(vt.get_value()/10))
self.play(vt.set_value, 5, run_time=5, rate_func=linear)
self.wait()
use `dt`
def orbit_moving(self):
orbit = Ellipse(color=WHITE).scale(3)
dot = Dot(radius=0.3, color=GREEN)
dot.move_to(orbit.point_from_proportion(0))
self.t_offset = 0
rate = 1
def update_func(mob, dt):
self.t_offset += (dt * rate)
mob.move_to(orbit.point_from_proportion(self.t_offset % 1))
dot.add_updater(update_func)
self.add(orbit, dot)
self.wait(1)
def orbit_moving_fullcircle(self):
orbit = Ellipse(color=WHITE).scale(3)
dot = Dot(radius=0.3, color=GREEN)
dot.move_to(orbit.point_from_proportion(0))
self.t_offset = 1/self.camera.frame_rate
rate = 0.5
self.t_idx = 1
def update_func(mob, dt):
self.t_offset += (dt * rate)
mob.move_to(orbit.point_from_proportion(self.t_offset % 1))
print(str(self.t_idx) + ":", str(dt), str(self.t_offset))
self.t_idx += 1
dot.add_updater(update_func)
self.add(orbit, dot)
self.wait(2)
dot.remove_updater(update_func)
self.wait(1)
dot.add_updater(update_func)
self.wait(2)
def orbit_moving_playing(self):
orbit = Ellipse(color=WHITE).scale(3)
dot = Dot(radius=0.3, color=GREEN)
dot.move_to(orbit.point_from_proportion(0))
self.t_offset = 1/self.camera.frame_rate
rate = 0.5
self.t_idx = 1
def update_func(mob, dt):
self.t_offset += (dt * rate)
mob.move_to(orbit.point_from_proportion(self.t_offset % 1))
print(str(self.t_idx) + ":", str(dt), str(self.t_offset))
self.t_idx += 1
dot.add_updater(update_func)
self.add(orbit, dot)
self.play(ShowCreation(dot), run_time=2)
dot.remove_updater(update_func)
self.wait(1)
dot.add_updater(update_func)
self.play(ShowCreation(dot), run_time=2)
self.wait(2)
반응형
'Programming > Manim code' 카테고리의 다른 글
[49] Update Animation class (0) | 2020.05.29 |
---|---|
[48]always_redraw (0) | 2020.05.29 |
[46]Mobject moving/coloring Animation (0) | 2020.05.29 |
[45]Special Effects (0) | 2020.05.29 |
[44]AnimationGroup (0) | 2020.05.20 |