诚城的成长 诚城的成长
首页
  • 高数基础
  • 数一

    • 高等数学
    • 线性代数
    • 概率论与数理统计
  • 820

    • 数据结构
    • 计算机操作系统
  • 英一

    • 单词
    • 语法
    • 阅读理解
    • 作文
  • 政治

    • 马克思主义基本原理
    • 毛泽东
    • 近代史
    • 思修
    • 时事
  • openpose
  • html5
  • css3
  • UI

    • Tailwind Css
    • Element-Plus
    • UniApp
  • 框架

    • Vue3
  • 拓展包

    • 包管理工具
    • 包开发
  • 开发语言

    • C语言
    • PHP
    • Phyton
  • 框架

    • Laravel
  • 会计

    • 初级经济法基础
    • 初级会计实务
  • 软考

    • 信息系统项目管理师
  • 博客

    • vitepress
    • vuepress
  • manim
  • git
  • vsCode
  • latex
  • docker
  • axios
  • vim
  • mac
  • Jetbrains

    • phpstorm
    • clion
突发奇想
GitHub (opens new window)

诚城

我有N个梦想……
首页
  • 高数基础
  • 数一

    • 高等数学
    • 线性代数
    • 概率论与数理统计
  • 820

    • 数据结构
    • 计算机操作系统
  • 英一

    • 单词
    • 语法
    • 阅读理解
    • 作文
  • 政治

    • 马克思主义基本原理
    • 毛泽东
    • 近代史
    • 思修
    • 时事
  • openpose
  • html5
  • css3
  • UI

    • Tailwind Css
    • Element-Plus
    • UniApp
  • 框架

    • Vue3
  • 拓展包

    • 包管理工具
    • 包开发
  • 开发语言

    • C语言
    • PHP
    • Phyton
  • 框架

    • Laravel
  • 会计

    • 初级经济法基础
    • 初级会计实务
  • 软考

    • 信息系统项目管理师
  • 博客

    • vitepress
    • vuepress
  • manim
  • git
  • vsCode
  • latex
  • docker
  • axios
  • vim
  • mac
  • Jetbrains

    • phpstorm
    • clion
突发奇想
GitHub (opens new window)
  • introduction
  • animation
  • position
  • Color
  • material
  • 数学

  • 视频进度条
  • manim
诚城
2022-01-27

视频进度条原创

说明 (opens new window)
基于ManimGL (opens new window)制作的视频进度条。

from manimlib.imports import *

class VideoProgressBar(VGroup):

    CONFIG = {
        'methods_dict': {
            '序言': '0025',
            'shift+move_to': '0210',
            'scale': '0402',
            'rotate': '0504',
            'flip': '0712',
            'stretch': '0901',
            'to_corner': '1014',
            'align_to': '1129',
            'next_to': '1227',
            'set_width+set_height': '1500',
            ' ': '1659'},
        'total_time': '1724',
        'text_font': "思源黑体 Bold",
        'color_list': [BLUE, PINK, RED, ORANGE, GREEN],
        'bar_width': 20,
        'text_size': 0.30,
    }

    def __init__(self, **kwargs):

        VGroup.__init__(self, **kwargs)

        func_time = lambda t: int(t[0:2]) * 60 + int(t[2:])
        func_loc = lambda t: func_time(t)/func_time(self.total_time) * FRAME_WIDTH * RIGHT + FRAME_WIDTH * LEFT / 2

        p_list = [FRAME_WIDTH * LEFT / 2]
        for v in self.methods_dict.values():
            p_list.append(func_loc(v))
        p_list.append(func_loc(self.total_time))

        self.colors = color_gradient(self.color_list, len(self.methods_dict)+1)

        self.lines = VGroup(*[Line(p_list[i], p_list[i+1]-0.02*RIGHT, color=self.colors[i], stroke_width=self.bar_width) for i in range(len(self.methods_dict)+1)])
        self.lines.to_edge(DOWN * 0.22, buff=1)
        self.texts = VGroup(*[Text(t, color=WHITE, font=self.text_font, size=self.text_size) for t in self.methods_dict.keys()], plot_depth=1)

        for i in range(len(self.methods_dict)):
            self.texts[i].move_to(self.lines[i+1])

        self.add(self.lines, self.texts)


class LeftProgressBar(Scene):
    '''
    用于导出制作左侧进度条上文字的场景
    目前细节需要微调
    推荐导出5120x2880像素,带透明度的pbg图像
    '''
    CONFIG = {
        'methods_dict': {
            '序言': '0025', 
            'shift': '0210', 
            'move_to': '0300',
            'scale': '0402',
            'rotate': '0504', 
            'flip': '0712', 
            'stretch': '0901',
            'to_corner': '1014', 
            'align_to': '1129',
            'next_to': '1227', 
            'set_width\nset_height': '1500',
        },
        'total_time': '1706',
        'text_font': "Consolas",
        'text_scale_factor': 0.7,
    }

    def construct(self):
        func_time = lambda t: int(t[0:2]) * 60 + int(t[2:])
        func_loc  = lambda t: func_time(t) / func_time(total_time) * FRAME_HEIGHT * UP + FRAME_HEIGHT * DOWN / 2
        p_list = [FRAME_HEIGHT * DOWN / 2]
        for v in methods_dict.values():
            p_list.append(func_loc(v))
        p_list.append(func_loc(total_time))
        print(p_list)

        texts = VGroup(
            *[
                Text(text, color=WHITE, font=self.text_font, size=0.4, background_stroke_color=WHITE).scale(self.text_scale_factor)
                for text in methods_dict.keys()
            ]
        )
        texts[-1].become(
            VGroup(
                Text('set_width', color=WHITE, font=self.text_font, size=0.4, background_stroke_color=WHITE).scale(self.text_scale_factor),
                Text('set_height', color=WHITE, font=self.text_font, size=0.4, background_stroke_color=WHITE).scale(self.text_scale_factor)
            ).arrange(DOWN, buff=0.04)
        )
        times = VGroup(
            *[
                Text("{}:{}".format(time[:2], time[2:]), color=WHITE, font=self.text_font, size=0.4, background_stroke_color=WHITE).scale(0.55)
                for time in methods_dict.values()
            ]
        )
        
        for i in range(len(methods_dict)):
            times[i].next_to(texts[i], DOWN, buff=0.05)
            texts[i].add(times[i])
            texts[i].move_to(p_list[i + 1])

        self.add(texts)
## to be tested ##
上次更新: 2022/08/24, 17:50:00
几何类

← 几何类

Theme by Vdoing | Copyright © 2022-2022 carveybunt | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×
×

特别申明:

本站所有内容均为个人理解或转载,如有不当之处,敬请大佬指导!