2021 November 05
Friday morning

A tradition

People have been writing 'Hello, World!' programs since about 1972. The object was to get a potentially complicated setup to do something simple.

When you see 'Hello, World!' on the screen, you can be reassured that you've figured out the correct compiler flags and now you can go and have some lunch.

Fast forward to 2021, when in Python the equivalent is literally print("Hello, World!"). I doubted the benefit of showing one here for Balladeer.

It turns out well that I did. In writing this I came across a few inconveniences which we could have done without. Those are all fixed now in version 0.12.0.

A design feature of Balladeer is the way it separates screen dialogue from functional code. To follow along, you'll need to create two new files; hello.rst for dialogue and for code.


Dialogue files are a reStructuredText markup format. They consist of a top level heading for the scene, and below that one or more shots. The titles for them can be whatever you like.

Here's everything that goes in this file:

Scene 1

Shot 1

Hello, World!

In this file goes the code we need to create the simplest possible Balladeer Story, then to animate and render it.

First we import a couple of classes:

from balladeer import Drama
from balladeer import Story

We'll need a Drama object, whose dialogue folder will reference the previous .rst file:

drama = Drama()
drama.folder = ["hello.rst"]

Now our Story object, whose context is that drama:

story = Story(context=drama)

Whenever we animate and render, we create a new Presenter object:

presenter = story.represent()

Under the hood, the Presenter here parses each Dialogue file (there is only one), checks its Entity constraints (there are none) against the Ensemble (which we left empty). It then parses each Shot into a frame.

We'll now iterate over the (one) frame, and animate it. Then iterate over each rendered line (only one again) and print it:

for frame in presenter.frames:
    animation = presenter.animate(frame)

    for line, duration in story.render_frame_to_terminal(animation):

Now the command python should show you:

Hello, World!

And after Lunch

From here, you can play at adding extra dialogue. Also check out Tea and Sympathy. The module shows how to accept text input and feed it as a command to the Drama. There'll be more on that here soon.

Comments hosted at Disqus