All writing

Essay3 min read

From optical caustics in Rust to shipping a 112-star macOS app

Learning Rust through a raindrop ray-tracer with glium and egui, and how that eventually turned into Petal — a native GPU-rendered disk explorer.

Snell's Law · raindrop caustic focus
Defaults match SimulationParams in my Rust caustics repo: water (n = 1.33) at 45°.

Most of my day job for the last decade has been web software: PHP, Laravel, Vue, TypeScript. If you only ever write web apps, Rust can look a little bit intimidating from the outside — lifetimes, borrow checkers, build times, all the usual scary stories.

I didn’t start learning Rust with a grand plan to ship a macOS app. I started by trying to draw the bright squiggly patterns sunlight makes when it passes through raindrops.

Starting with something purely visual (caustics)

Optical caustics are a great excuse to learn a systems language because you immediately know when your maths is broken: the screen is either black or looks completely wrong.

My caustics repo was a small desktop sandbox using nalgebra for vectors, rayon for parallel ray loops, glium for OpenGL rendering, and egui for sliders so I could tweak things live. The core struct in simulation.rs was pretty modest:

rust
SimulationParams {
    raindrop_radius: 0.3,
    raindrop_count: 200,
    refractive_index: 1.33, // water
    light_angle: 45.0,
    wavelength: 550.0,
    ray_count: 2000,
    max_bounces: 3,
    grid_size: 60,
    grid_spacing: 0.15,
}

If you drag the two sliders in the Snell’s law diagram at the top of this post, you can see the exact bit that hooked me: uniform parallel light goes into a curved surface, refracts twice (air → water → air), and bunches up onto a sharp bright envelope on the surface below. Nudge the refractive index up toward glass (1.52) or shift the light angle, and the focal curve slides and tightens immediately.

As a piece of software, caustics was never going to be a product. What it did give me was muscle memory in Rust: data-oriented structs, splitting heavy CPU loops off the render thread, not panicking when the borrow checker complains, and getting comfortable shipping native graphics instead of a browser tab.

Carrying that into a real annoyance: Petal

A bit later, I got properly fed up with clearing disk space on my Mac.

Existing disk visualisers all annoyed me in slightly different ways. Either they sat on a loading spinner for half a minute before drawing anything, or they showed logical sizes that didn’t match what APFS actually frees when you have clones, hard links, and Time Machine snapshots, or they’d happily let you bin something you really shouldn’t touch.

Because I already felt at home in Rust by that point, I decided to build Petal natively using GPUI — the GPU-rendered UI framework Zed is built on.

Going from a toy ray-tracer to an app other people actually install on their Macs is a funny jump. Almost none of the hard work ends up being "how do I write Rust?". It’s all the quiet UX and operating-system edge cases:

  • Drawing while scanning. Using getattrlistbulk and openat, Petal streams directory sizes straight into the sunburst, icicle, or treemap while the walk is still running. Muted slices settle into full colour as their subtrees finish, then fold smoothly into size order.
  • Keeping hover stable while the world moves. When a live scan keeps updating the tree, naïve hit-testing makes your hovered slice jump around underneath the cursor. Keeping selection and hover anchored cleanly while counts climb makes the whole app feel ten times calmer.
  • Not letting users shoot themselves in the foot. Petal refuses to offer parts inside .app bundles for Trash, splits cleanup findings into Safe to delete, Review first, and Manage in app, and never silently runs git gc on your repos — it just hands you the commands to inspect and paste yourself.
  • Testing APFS maths against a real disk. Rather than trusting documentation, the test suite creates a throwaway APFS volume, writes real clones and hard links, deletes them, and asserts that Petal’s predicted reclaimable bytes match what macOS actually frees.

Why weird toy projects matter

Petal ended up picking up over a hundred stars on GitHub, a Homebrew tap, and genuinely helpful bug reports from people running it on their own machines.

I don’t think I would have built it if I hadn’t first spent weekends messing around with glium, nalgebra, and water droplets for no commercial reason at all. Toy projects lower the stakes enough that you actually learn the tools properly — and then one day a real problem turns up and your fingers already know what to reach for.

If you want to poke at Petal (or check what’s quietly eating 40 GB on your SSD), it’s MIT-licensed at github.com/henrydennis/petal.