示例#1
0
def demo_commenting(scene: CodeScene):
    scene.add_background(f"{example_dir}/resources/blackboard.jpg")

    code = scene.animate_code_comments(
        title="examples/commented.py",
        path=f"{example_dir}/commented.py",
        keep_comments=True,
        start_line=6,
        end_line=19,
        reset_at_end=False,
    )

    scene.highlight_line(
        code,
        number=6,
        caption="These caption callouts are "
        "automatically generated from comments when "
        "using animate_code_comments()",
    )
    scene.highlight_lines(
        code,
        start=14,
        end=18,
        caption="You can also highlight multiple "
        "lines by ending the block with '# "
        "end'",
    )
    scene.highlight_none(code)
    scene.play(FadeOut(code))
    scene.clear()
示例#2
0
def demo_highlighting(scene: CodeScene):
    title = PangoText(
        """
        If you want more control, you can create code blocks and
        highlight them manually.
        """,
        font="Helvetica",
        line_spacing=0.5,
    ).scale(0.7)
    scene.play(ShowCreation(title, run_time=3, rate_func=linear))
    scene.wait(2)
    scene.clear()

    scene.add_background(f"{example_dir}/resources/blackboard.jpg")
    tex = scene.create_code(f"{example_dir}/highlights.py")
    scene.play(ShowCreation(tex))
    scene.highlight_line(
        tex,
        11,
        caption=
        "Create code blocks yourself and pass in any arguments the Code class supports to do things "
        "like change the theme or font",
    )
    scene.highlight_lines(
        tex,
        13,
        19,
        caption=
        "Highlight code with a caption to give extra information. A wait is"
        " automatically added for a time based on the length of the caption",
    )
    scene.highlight_line(tex, 21, caption="Reset highlighting and positioning")
    scene.highlight_none(tex)
    scene.play(FadeOut(tex))
    scene.clear()