ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

manim updater animations

2022-06-11 16:33:23  阅读:200  来源: 互联网

标签:play get color self stroke updater animations circle manim


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)

标签:play,get,color,self,stroke,updater,animations,circle,manim
来源: https://www.cnblogs.com/daxiangcai/p/16365698.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有