Learn creative coding writing simple programs

91. Timelines: tell a story

In this episode we discover a way to run several programs one after another. We can decide how long each program runs. This can be used to show different scenes, for example some welcome text, then an animation, and finally some credits showing the date and the author of the program. But it can also be used to tell stories, for example by showing a dialog where different characters speak in turns.
To measure time we use the function millis(), which tells us for how long the program has been running. It returns an integer with the number of milliseconds since the program started. One second is one thousand millisecods.
Using the if() statement we can decide if certain lines in the program should execute or not. When we use if-else we can decide between two different options. That means that we are deciding if to run one line (or group of lines) or a different line (or group of lines).
In this episode we introduce the complete if() statement, that includes if-elseif-elseif-else. This allows us to have not only two options, but many options, one of which will execute depending on the conditions we write.

Tags: elseif, millis, story, timeline

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```