Interactive Winter Wonderland.
Imagine a winter wonderland at your fingertips!
Is an interactive holiday-themed display built using a Raspberry Pi Zero 2 W, SDL2 graphics, and touchscreen input.
Watch snowflakes dynamically fall with wind effects, and use touch gestures to switch between festive backgrounds.
This project combines engaging visuals, responsive interaction, and scalable customization to create the perfect holiday centerpiece for any screen.
This project simulates falling snow on a customizable screen resolution, with interactive background switching via touchscreen. It uses SDL2 for rendering graphics and libevdev for touchscreen input handling.
The program is designed to be lightweight, modular, and extensible.
- Raspberry Pi (e.g., Raspberry Pi Zero 2 W)
- Touchscreen Display (e.g., Pimoroni HyperPixel or any HDMI touchscreen)
- Install Raspberry Pi OS on your Raspberry Pi.
- We don't need to use GUI, so the Lite version is enough.
- Update and upgrade the system:
sudo apt-get update && sudo apt-get upgrade -y
- Install the required libraries:
sudo apt-get install libsdl2-dev libsdl2-image-dev libevdev-dev
2. Cloning the RepositoryClone the project repository from GitHub:
git clone git@github.com:feiticeir0/ChristmasSnowGlobe.git
cd ChristmasSnowGlobe
3. Adding Background ImagesAdd your .jpg
background images to the images
directory in the project folder. For example:
ChristmasSnowGlobe/
├── images/
│ ├── background1.jpg
│ ├── background2.jpg
│ └── background3.jpg
└── christmasSnowGlobe
4. Building the ProgramUse the included Makefile to compile the project:
make
5. TouchYou probably need to add your user (or the user running this program) to the input group. Check with your distro for the correct group.
sudo usermod -aG input $USER
6. Running the ProgramRun the program with the required arguments:
./christmasSnowGlobe -w 720 -h 720 -e /dev/input/event0
-w
: Screen width (e.g., 720).-h
: Screen height (e.g., 768).-e
: Touchscreen input device (e.g.,/dev/input/event0
).
To view the help message:
./christmasSnowGlobe --help
7. AutostartTo autostart the program when the Raspberry PI starts or reboots, we can use our.basrc file.
Just configure the Raspberry PI OS to auto login to cli:
1. System Options > S5 Boot / Auto Login > B2 Console Autologin
Next, edit your.basrc to execute the program once you login.
vi .bashrc
And place the following line at the end of the file:
cd ChristmasSnowGlobe;./christmasSnowGlobe -h 720 -w 720 -e /dev/input/event0 &
Save and exit.
NOTE: We need to execute it inside the directory because of the images path. Something to change in a next release.
Reboot your RPi and see if it works.
If using Pimoroni's Hyperpixel Touch 4.0 screen
Using Pimoroni's Hyperpixel Square 4.0, sometimes the touch device changes between reboots. So, it may not always be event0.
I've created a script to find the correct touch device for the Pimoroni's Hyperpixel Touch 4.0. This way, when invoking the Christmas Snow Globe, I always have the right device.
To use the script to find the device, the correct invocation is:
cd ChristmasSnowGlobe;./christmasSnowGlobe -h 720 -w 720 -e /dev/input/$(./findPimoronisTouchDevice.sh) &
The script findPimoronisTouchDevice.sh returns the correct event device for the touch screen.
CustomizationAdding Your Own Backgrounds- Replace or add
.jpeg
images in theimages
directory. - The program automatically detects all
.jpg
files in the folder.
You can modify the following aspects in the code:
- Number of Snowflakes:
#define NUM_SNOWFLAKES 80
- Wind Speed and Acceleration:
float wind_speed = 0.0f;
float wind_acceleration = 0.02f;
- Snowflake Speed and Size:
snowflake->size = rand() % 3 + 2;
snowflake->speed = (float)(rand() % 300 + 200) / 100.0f;
Scaling for Larger DisplaysModify the screen resolution via the command-line arguments or adjust the default values in the code:
int width = 1024;
int height = 768;
Code Explanation1. Initialization- The program initializes SDL2, SDL2_image, and
libevdev
for rendering graphics and handling touch input. - Command-line arguments allow setting screen width, height, and the touchscreen device path.
./snow_simulation -w 720 -h 720 -e /dev/input/event0
If
you're using the Pimoroni's Hyperpixel touch 4.0 screen, every time the Raspberry PI boots, the touch device can change. This invalidates an automatic execution.- I developed a script that will detect the touch device. This way, I can always pass the correct device to the program.
- Each snowflake is represented by a struct containing its position, size, and speed.
- Snowflakes are updated dynamically to simulate falling with wind effects.
typedef struct {
int x, y, size;
float speed;
} Snowflake;
3. Dynamic Backgrounds- Background images are loaded from the
images
directory usingSDL2_image
. - Touch events cycle through the loaded backgrounds.
int load_textures(SDL_Renderer *renderer, const char *directory, SDL_Texture ***textures);
4. Touchscreen Integration- The program uses
libevdev
to read raw input events from the touchscreen device. - The
EV_ABS
andEV_SYN
events detect touch positions and release states.
while (libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev) == 0) {
if (ev.type == EV_ABS) {
if (!is_touch_active) {
current_background = (current_background + 1) % num_backgrounds;
is_touch_active = 1;
}
}
}
Touch deviceTo find out your touch device, you can install evtest and use it to find the device:
sudo apt install evtest
Run the software
sudo evtest
It should list some devices and one of the them is your touch device.Here's an example using Pimoroni's HyperPixel 4.0 Square
evtest
No device specified, trying to scan all of /dev/input/event*
Not running as root, no devices may be available.
Available devices:
/dev/input/event0: vc4-hdmi
/dev/input/event1: 11-0048 EP0110M09
/dev/input/event2: vc4-hdmi HDMI Jack
Select the device event number [0-2]:
Select one, touch it and see if outputs text.
If you see text, that's the one you should use.
Exit the applicationTo exit the program, we have to kill it.
In a terminal, execute the following script to kill the snow wonderland:
kill -9 $(pidof christmasSnowGlobe)
Future ImprovementsHere are some improvements that I'm hoping to make:
- Dynamic Background Scaling: Automatically scale backgrounds to fit the screen resolution.
- Audio Integration: Add festive music or sound effects.
- Enhanced Visual Effects: Introduce twinkling lights or a dynamic weather system.
- Exit Cleanly: Find a way to exit the software without having to kill it.
I hope you enjoy creating and customizing your own Interactive Winter Wonderland!
Add your family photos or favorite holiday scenes to make it uniquely yours and create a cozy, festive atmosphere for everyone to enjoy.
Have fun, and let your creativity snowball into the perfect holiday project! ❄️
Comments
Please log in or sign up to comment.