There are three main components to the snow globe:

  • The background image
  • The flakes
  • The snow on the ground

Something like this:

Let's talk about each of these.

Background

This one is pretty simple. It's just an image or a solid color. There's really nothing for it to do other than just sit there. So there's no more code associated with it other than loading it and showing it.

We'll pretty much just do what is described here and then leave it alone.

Flakes

These are the pretty little snowflakes that come falling out of the sky. We will use little bitmaps to give them shape. We will also allow for a few different fall speeds, so they all don't just fall at the same rate. The other thing that needs to be done is check if they have hit the ground - the current snow level.

To actually make the flakes move, all that needs to be done is change the y value of their associated TileGrid. This is a CircuitPython displayio feature. For more info see here and here. So basically, each flake will be a separate TileGrid, and we will change the y value of each to make them fall.

Snow

This is the snow on the ground. At the beginning, there is no snow on the ground. As the flakes fall and hit the ground, snow will be added in the general area where the flake hit. So this level will grow as more and more flakes fall.

We'll use a displayio Bitmap to represent the snow. The bitmap size will be the same as the screen size. It will start empty - totally transparent. To "add snow" we will just set individual pixels to the snow color.

This guide was first published on Nov 02, 2019. It was last updated on Nov 02, 2019.

This page (How It Works) was last updated on Oct 22, 2021.

Text editor powered by tinymce.