manim updater animations

2022/6/11 23:50:20

本文主要是介绍manim updater animations,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Scene1

创建长方体并移动:

class myjob(Scene):
    def construct(self):
        box = Rectangle(stroke_color = GREEN_C, stroke_opacity = 0.7, fill_color = RED_B, fill_opacity = 0.5, height = 1, widhth = 1)
        self.add(box)
        self.play(box.animate.shift(RIGHT*2), run_time = 2)

 

Scene2

创建坐标轴,并让圆变化成三角形

class myjob(Scene):
    def construct(self):
        axes = Axes(x_range = [-3,3,1], y_range = [-3,3,1], x_length = 6, y_length = 6)
        axes.to_edge(LEFT, buff = 0.5)

        circle = Circle(stroke_width = 6, stroke_color = YELLOW, fill_color = RED_C, fill_opacity = 0.8)
        circle.set_width(2).to_edge(DR, buff = 0)

        triangle = Triangle(stroke_color = ORANGE, stroke_width = 10, fill_color = GREY)
        triangle.set_height(2).shift(DOWN*3 + RIGHT*3)

        self.play(Write(axes))
        self.play(DrawBorderThenFill(circle))
        self.play(circle.animate.set_width(1))
        self.play(Transfrorm(circle,triangle), run_time = 3)

 

Scene3

生成一个移动的矩形,同时中心有个文本跟着移动

class myjob(Scene):
    def construct(self):
        rectangle = RoundedRectangle(stroke_width = 8, stroke_color = WHITE, fill_color = BLUE_B, width= 4.5, height =2).shift(UP*3 + LEFT*4)

        mathtext = MathTex("\\frac{3}{4} = 0.75").set_color_by_gradient(GREEN, PINK).set_height(1.5)
        mathtext.move_to(rectangle.get_center())
        mathtext.add_updater(lambda x : x.move_to(rectangle.get_center()))  # 这样文本可以保持在矩形中心

        self.play(FadeIn(rectangle))
        self.play(Write(mathtext))
        self.play(rectangle.animate.shift(RIGHT*1.5 + DOWN*5), run_time = 6)
        self.wait()
        mathtext.clear_updaters()  # 清除跟踪
        self.play(rectangle.animate.shift(LEFT*2 + UP*1), run_time = 6)

 

Scene4

class myjob(Scene):
def construct(self):
r = ValueTracker(0.5)

circle = always_redraw(lambda : Circle(radius = r.get_value(), stroke_color = YELLOW, stroke_width = 5)) # like adding an updater without the ability to clear it, always update

line_radius = always_redraw(lambda : Line(start = circle.get_center(), end = circle.get_bottom(), stroke_color = RED_B, stroke_width = 10)) # always update

line_circumference = always_redraw(lambda : Line(stroke_color = YELLOW, stroke_width = 5).set_length(2*r.get_value()*PI).next_to(circle, DOWN, buff = 0.2))  # 注意不要将括号写错位了!

triangle = always_redraw(lambda : Polygon(circle.get_top(), circle.get_left(), circle.get_right(), fill_color = GREEN_C))

self.play(LaggedStart(Create(circle), DrawBorderThenFill(line_radius), DrawBorderThenFill(triangle), run_time = 4, lag_radio = 0.75))
self.play(ReplacementTransform(circle.copy(), line_circumference), run_time = 2)
self.play(r.animate.set_value(2), run_time = 5)



这篇关于manim updater animations的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程