Nannou/Rust tutorial based on Schotter by Georg Nees
Nannou/Rust tutorial based on Schotter by Georg Nees
Schotter (German for gravel) is a piece by computer art pioneer Georg Nees. It consists of a grid of squares 12 across and 22 down with random rotation and displacement that increases towards the bottom.
The original was created using a pen plotter. I don't know if Dr. Nees had access to a graphics terminal (fairly rare at the time) to preview the result or if he ran the program multiple times to get different results before choosing this as the final.
Schotter is fairly simple to code; at least it is today with modern graphics libraries. Several other people have written tutorials for how to code this using various platforms. I'm adding to this collection with a series of tutorials for coding it in Rust using the nannou library.
This tutorial assumes you are familiar with the Rust language and, if you will be following along (which I certainly encourage), access to a working Rust coding environment. We will be using a Rust "workspace", which allows grouping multiple related programs together. (You can learn more about workspaces in chapters of The Rust Programming Language or The Cargo Book.)
Here are the steps I use for creating a Rust workspace:
[workspace]
members=[ ]
resolver="3"
[workspace.dependencies]
nannou = "0.20"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3The "members" is a list of workspace members; we'll add our variations to it as we go. Nannou requires it to be at least "2", but we'll use the latest: "3".
The "workspace.dependencies" section lists the common dependencies for the projects in the workspace. Specifying the version of nannou here allows changing it in a single place when we need to change it.
Nannou is updated frequently with new features and bug fixes, so when you start a new project, you may want to be sure you are using the latest version of nannou. You can look that up with the command cargo search nannou. The output will contain a line such as the following:
nannou = "0.20.0" # A Creative Coding Framework for Rust.When I first wrote this in May 2021, the latest version was 0.16.0, but a new version was released the next month so I updated this tutorial to use 0.17.0. This actually required changing some of the code since the parameters for the random number generator function gen_range() changed (we'll see this in schotter2). When version 0.18.0 was released five months later, yet more changes were needed. And when version 0.20.0 was released five years later, even more changes were needed. Specifying the exact version of the libraries in Cargo.toml prevents changes from breaking our code when libraries are updated.
The "profile" sections determine what optimization level to use. The first one specifies a low optimization level for the programs in our workspace and the other specifies a high optimization level for the packages it uses (such as nannou). This allows debugging to be used for our programs but makes nannou run much faster.
Optionally initialize configuration management for that directory. I like to use git for this. When I get something I like (and that works), I commit the files in git. Then as I make changes, I can easily compare what I have done to that version, and I can easily revert back to that version if I really mess things up and want to start again. This also makes it easy to publish the result online (for example, on GitHub). There are two steps:
Initialize the repository. This can be done with the command line (git init). Alternatively, many editors have a method to do this. For example, in VS Code go to the Source Control view (Ctrl+Shift+G) and click Initialize Repository.
Create a file ".gitignore" containing the files that should not be managed by git. For Rust programs there are two:
/target
Cargo.lockOptionally create standard information files in the directory:
We'll be coding Schotter four different ways, each building on the previous version. Click a link for a short tutorial; they are designed to be done in order. You can find the end result for each tutorial in the appropriate directory.
Schotter1: Use the nannou "sketch" facility to code a simple version with no frills.
Schotter2: Change the code to a nannou "app" with persistent data and simple keyboard commands to adjust some parameters.
Schotter3: Add a control panel using egui to make it easier to adjust parameters on the fly.
Schotter4: Animate the squares, so they move from the starting grid to their displaced positions, and from there to new positions.
I may add some variations later; after all, that's what creative coding is all about! They may or may not be accompanied by full tutorials. But that's it for now.
Note: This tutorial was updated for nannou version 0.20.0, released in June 2026. This was a major update, rewriting it to use the Bevy game engine. And there are a few glitches in the first version using Bevy. The ones that affect the tutorial are described along with workarounds to make the tutorial work.
No open issues yet, or sync has not completed.