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()
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()
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()
def demo_sequence(scene: CodeScene): title = PangoText( """ 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="Helvetica", line_spacing=0.5, ).scale(0.7) scene.play(ShowCreation(title, run_time=4, rate_func=linear)) scene.wait(3) scene.clear() scene.add_background(f"{example_dir}/resources/blackboard.jpg") diagram = SequenceDiagram() browser, web, app = diagram.add_objects("Browser", "Web", "App") with browser: with web.text("Make a request"): web.to_target("Do a quick thing", app) with app.text("Retrieve a json object"): app.to_self("Calls itself") app.note("Do lots and lots and lots of thinking") app.ret("Value from db") web.ret("HTML response") diagram.animate(scene) scene.wait(3) scene.play(FadeOut(diagram)) scene.clear()
def demo_render_self(scene: CodeScene): scene.add_background(f"{example_dir}/resources/blackboard.jpg") # Here is the code rendering this video you are watching now! code = scene.animate_code_comments( title="examples/intro.py", path=f"{example_dir}/intro.py", keep_comments=True, start_line=92, end_line=108, reset_at_end=False, ) # end scene.wait(2) scene.play(FadeOut(code)) scene.clear()
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()
def demo_boxes(scene: CodeScene): scene.add_background(f"{example_dir}/resources/blackboard.jpg") lib = Library() comp1 = lib.text_box("Component A", shadow=False) comp2 = lib.text_box("Component B", shadow=False) comp3 = lib.text_box("Component C", shadow=False) comp1.to_edge(LEFT) comp2.next_to(comp1, DOWN, buff=1) comp3.next_to(comp1, RIGHT, buff=4) arrow1 = lib.connect(comp2, comp1, "Do something") arrow2 = lib.connect(comp1, comp3, "Do another thing") scene.play(FadeIn(comp2)) scene.wait_until_beat(1) scene.play(ShowCreation(arrow1)) scene.play(FadeIn(comp1)) scene.wait_until_beat(1) scene.play(ShowCreation(arrow2)) scene.play(FadeIn(comp3)) scene.wait_until_beat(4) scene.clear()