Recreating macOS’s Drift screensaver with Rust and Wasm

164 points sandy_doo

​

Flux – an ode to the macOS Drift screensaver.

A few years ago Apple shipped macOS Catalina and with it came a little gift – a gorgeous new screensaver called Drift. I’ve since become somewhat of an ardent fanatic of this screensaver, so I thought I’d have a go at figuring out how it works.

​

After a few months of research and getting to know Rust, you can now try it out in your browser and even play around with the settings on the fly: https://flux.sandydoo.me/

​

Most of it is written in Rust and compiles to Wasm with WebGL/OpenGL bindings via glow. The settings panel is written in Elm and the whole project is compiled with Nix. There’s also a very basic native desktop app. I haven’t seen many examples of a complete setup like this, so hopefully this can serve as a template for anyone trying out a similar stack.

​

So how does this work then?

At its core this is a fluid simulation. Yeah, I know, a bit much for a screensaver! The fluid part is based on a classic design pioneered by Jos Stam and later described in a chapter of GPU Gems. You inject a bit of simplex noise, run the fluid simulation, and then, instead of advecting a colorful dye, you advect the endpoints of a fixed grid of lines.

​

Let me know what you think! Anything you’d like to see added? Mouse interaction? Color schemes from images?

​

The code is open-source on GitHub: https://github.com/sandydoo/flux

I post in-progress tweets here: https://twitter.com/sandy\_doo