コード例 #1
0
def demo_boxes(scene: CodeScene):
    scene.add_background(f"{example_dir}/resources/blackboard.jpg")

    title = Text("examples/boxes.py", font=DEFAULT_FONT)
    title.to_edge(UP)
    scene.add(title)
    comp1 = TextBox("Component A", shadow=False)
    comp2 = TextBox("Component B", shadow=False)
    comp3 = TextBox("Component C", shadow=False)
    comp1.next_to(title, DOWN, buff=2)
    comp1.to_edge(LEFT)
    comp2.next_to(comp1, DOWN, buff=1)
    comp3.next_to(comp1, RIGHT, buff=4)
    arrow1 = Connection(comp2, comp1, "Do something")
    arrow2 = Connection(comp1, comp3, "Do another thing")

    scene.play(FadeIn(comp2))
    scene.wait_until_beat(1)
    scene.play(Create(arrow1))
    scene.play(FadeIn(comp1))
    scene.wait_until_beat(1)
    scene.play(Create(arrow2))
    scene.play(FadeIn(comp3))

    scene.wait_until_beat(4)
    scene.clear()
コード例 #2
0
def overview(scene):
    title = Text(
        """
    Manim is a Python library used to generate videos,
    and Code Video Generator extends it to make it easy
    to generate code-related videos
    ... in fact, it is what was used to generate this video!
    """,
        font="Helvetica",
        line_spacing=0.5,
    ).scale(0.7)
    scene.play(Create(title, run_time=10, rate_func=linear))
    scene.wait(3)
    sub = (Text(
        """
        Here is an example:
        """,
        font="Helvetica",
    ).scale(0.7).next_to(title,
                         direction=DOWN,
                         buff=MED_LARGE_BUFF,
                         aligned_edge=LEFT))
    scene.play(Create(sub))
    scene.wait(2)
    scene.clear()
コード例 #3
0
def test_animationgroup_is_passing_remover_to_nested_animationgroups():
    scene = Scene()
    sqr_animation = Create(Square())
    circ_animation = Write(Circle(), remover=True)
    polygon_animation = Create(RegularPolygon(5))
    animation_group = AnimationGroup(
        AnimationGroup(sqr_animation, polygon_animation), circ_animation, remover=True
    )

    scene.play(animation_group)
    scene.wait(0.1)

    assert sqr_animation.remover
    assert circ_animation.remover
    assert polygon_animation.remover
コード例 #4
0
    def construct(self):

        comp1 = TextBox("Component A", shadow=False)
        comp2 = TextBox("Component B", shadow=False)
        comp3 = TextBox("Component C", shadow=False)
        comp1.to_edge(LEFT)
        comp2.next_to(comp1, DOWN, buff=1)
        comp3.next_to(comp1, RIGHT, buff=4)
        arrow1 = Connection(comp2, comp1, "Do something")
        arrow2 = Connection(comp1, comp3, "Another thing")

        self.play(FadeIn(comp2))
        self.play(Create(arrow1))
        self.play(FadeIn(comp1))
        self.play(Create(arrow2))
        self.play(FadeIn(comp3))

        self.wait(5)
コード例 #5
0
def demo_sequence(scene: CodeScene):
    title = Text(
        """
        You can use Code Video Generator to also illustrate
        high-level concepts through sequence diagrams, or
        if you want more control, your own block diagrams:
        """,
        font=DEFAULT_FONT,
        line_spacing=0.5,
    ).scale(0.7)
    scene.play(Create(title, run_time=4, rate_func=linear))
    scene.wait(3)
    scene.clear()

    scene.add_background(f"{example_dir}/resources/blackboard.jpg")

    title = Text("examples/sequence-diagrams.py", font=DEFAULT_FONT)
    title.to_edge(UP)
    scene.add(title)

    diagram = AutoScaled(SequenceDiagram())
    browser, web, app = diagram.add_objects("Browser", "Web", "App")

    browser.to(web, "Make a request")
    web.to(app, "Request with no response")
    web.to(app, "Retrieve a json object")
    app.to(app, "Calls itself")
    app.note("Do lots and lots and lots of thinking")
    app.to(web, "Value from db")
    web.to(browser, "HTML response")

    diagram.next_to(title, DOWN)
    scene.play(Create(diagram))
    for interaction in diagram.get_interactions():
        scene.play(Create(interaction))
    scene.wait(3)
    scene.play(FadeOut(diagram),
               *[FadeOut(item) for item in diagram.interactions])
    scene.clear()
コード例 #6
0
    def animate_code_comments(
        self,
        path: str,
        title: str = None,
        keep_comments: bool = False,
        start_line: int = 1,
        end_line: Optional[int] = None,
        reset_at_end: bool = True,
    ) -> Code:
        """
        Parses a code file, displays it or a section of it, and animates comments

        Args:
            path: The source code file path
            title: The title or file path if not provided
            keep_comments: Whether to keep comments or strip them when displaying
            start_line: The start line number, used for displaying only a partial file
            end_line: The end line number, defaults to the end of the file
            reset_at_end: Whether to reset the code to full screen at the end or not
        """
        code, comments = comment_parser.parse(path,
                                              keep_comments=keep_comments,
                                              start_line=start_line,
                                              end_line=end_line)

        tex = AutoScaled(
            PartialCode(code=code,
                        start_line=start_line,
                        style=self.code_theme))
        if title is None:
            title = path

        title = Text(title, color=WHITE).to_edge(edge=UP)
        self.add(title)
        tex.next_to(title, DOWN)

        self.play(Create(tex))
        self.wait()

        for comment in comments:
            self.highlight_lines(tex, comment.start, comment.end,
                                 comment.caption)

        if self.caption:
            self.play(FadeOut(self.caption))
            self.caption = None

        if reset_at_end:
            self.play(HighlightNone(tex))
            self.play(ApplyMethod(tex.full_size))
        return tex
コード例 #7
0
def title_scene(scene):

    scene.add_background(f"{example_dir}/resources/blackboard.jpg")
    title = Text("How to use Code Video Generator", font="Helvetica")
    scene.play(Create(title))
    scene.play(
        FadeIn(
            Text(f"Code and examples from version {__version__}",
                 font="Helvetica").scale(0.6).next_to(title,
                                                      direction=DOWN,
                                                      buff=LARGE_BUFF)))

    scene.wait(3)
    scene.clear()
コード例 #8
0
def test_animationgroup_is_passing_remover_to_animations(
        animation_remover, animation_group_remover):
    scene = Scene()
    sqr_animation = Create(Square(), remover=animation_remover)
    circ_animation = Write(Circle(), remover=animation_remover)
    animation_group = AnimationGroup(sqr_animation,
                                     circ_animation,
                                     remover=animation_group_remover)

    scene.play(animation_group)
    scene.wait(0.1)

    assert sqr_animation.remover
    assert circ_animation.remover
コード例 #9
0
def goodbye(scene: CodeScene):
    title = Text(
        """
        Try Code Video Generator today at:

          https://github.com/sleuth-io/code-video-generator

        Thanks for watching!""",
        font="Helvetica",
        line_spacing=0.5,
    ).scale(0.7)
    title.to_edge(LEFT)
    scene.play(Create(title, run_time=4, rate_func=linear))
    scene.wait(5)
    scene.play(FadeOut(title))
コード例 #10
0
    def construct(self):
        example_dir = dirname(__file__)
        self.add_background(f"{example_dir}/resources/blackboard.jpg")
        diagram = AutoScaled(SequenceDiagram())
        browser, web, app = diagram.add_objects("Browser", "Web", "App")

        browser.to(web, "Make a request")
        web.to(app, "Do a quick thing")
        web.to(app, "Retrieve a json object")
        app.to(app, "Call itself")
        app.note("Do lots and lots and lots of thinking")
        app.to(web, "Value from db")
        web.to(browser, "HTML response")

        title = Text("Sequence Diagram", font=DEFAULT_FONT, size=0.8)
        title.to_edge(UP)
        self.add(title)
        diagram.next_to(title, DOWN)

        self.play(Create(diagram))
        for interaction in diagram.get_interactions():
            self.play(Create(interaction))

        self.wait(5)