#coding:utf-8
#pip install manim
#ffmpeg官网 http://ffmpeg.org/
from manim import *
class Draw(Scene):
    def construct(self):
        text1 = Text(
            'Hello World',
            t2c={'[:1]': '#3174f0', '[1:2]': '#e53125',
                 '[2:3]': '#fbb003', '[3:4]': '#3174f4',
                 '[4:5]': '#269a43', '[5:6]': '#e53125',
                 '[6:7]': '#3174f3', '[7:8]': '#e53125',
                 '[8:9]': '#fbb003', '[9:]': '#317460'}, font_size=60)
        self.play(Create(text1))
        self.play(text1.animate.scale(2))
        self.wait()

# manim -pql manim_text.py Draw

 

#coding:utf-8
#pip install manim
#ffmpeg官网 http://ffmpeg.org/
from manim import *

# 设置文本大小
class Demo2(Scene):
    def construct(self):
        # WaterMark.construct(self)
        s = "Python数据之道"
        t1 = Text(s)
        t1.to_edge(UP,buff=0.5)
        t2 = Text(s).scale(2)
        t2.next_to(t1,DOWN)
        t3 = Text(s).set_width(10)
        t3.next_to(t2,DOWN)
        t4 = Text(s,font_size=40)
        t4.next_to(t3,DOWN)       
        self.add(t1)
        self.play(Write(t2))
        self.play(Create(t3))
        self.play(Write(t4))
        self.wait()


class Code1(Scene):
    def construct(self):
        # WaterMark.construct(self)
        code_str_1 = """
        def quickSort(Array):  
            n = len(Array)
            if n <= 1:
                return Array
            baseline = Array[0]
            left = [Array[i] for i in range(1, len(Array)) if Array[i] < baseline] 
            right = [Array[i] for i in range(1, len(Array)) if Array[i] >= baseline]
            return quickSort(left) + [baseline] + quickSort(right)
        """
        code1 = Code(
            code=code_str_1,
            tab_width=4,
            background="window",
            language="Python",
            font="Monospace",
            insert_line_no=False,  # 是否显示代码行数
            style='monokai',
        )
 
        code1.scale(0.8).to_edge(UP,buff=1)
 
        self.play(Write(code1))
        self.wait()

  manim -pql manim_text.py Demo2

       manim -pql manim_text.py Code1

 

 

  

 posted on 2023-11-28 11:40  boye169  阅读(19)  评论(0编辑  收藏  举报