Sheet 08 of 09 · Electrical/CS · Art
Math Departmental Study
Four projects from a math departmental study on applying mathematics to computer science: an Eulerian fluid solver, Lenia cellular automata, PID control of a coffee roaster and atmospheric scattering shaders.

A collection of small projects from my senior-year high school math departmental study, exploring how mathematics applies to computer science. The goal was project-based learning: pick a mathematical topic, study how others implemented it and why, build my own version, and look for places to improve or extend it. Having to build each one forced me to understand the concept well enough to explain it. All of the code is in a public GitHub repository.
1. Fluid simulation. An Eulerian grid-based fluid solver in Python, built from several papers and tutorials. Each step runs four stages: add forces to the cells, advect the fluid by self-advection, diffuse the dye and pressure, then compute a pressure correction so inflow and outflow in each cell sum to zero. It produces animations of dye moving through the fluid. It was very slow even at low resolution (speed was never the goal), and the dye concentration plots may be mis-normalized, which points to a bug I did not track down. It was still good practice in writing numerical code.
2. Cellular automata. Grid-based simulations where each cell updates by a simple ruleset: Conway's Game of Life, Wolfram's elementary automata, and the continuous generalizations Smooth Life and Lenia. Lenia replaces the ruleset with a convolution against a kernel followed by a growth mapping, and Game of Life can be written that way too. I implemented Life, Smooth Life, Lenia and modified Lenia in Python with different kernels and growth functions, using FFT-based convolution (scipy fftconvolve) to make them fast. I wanted to find a stable Lenia with conservation of mass, experiment with rulesets, and possibly try fractal-based automata.
3. Coffee roaster. The fluid bed roaster from its own project page, used here as the control-theory part of the study. The challenges were maximizing bean movement while minimizing airflow over the heating element, placing the thermocouple for good readings, and controlling temperature with a PID loop built into Artisan. The bean temperature responds very slowly to heater input, a smooth rate of rise matters for the roast, and bad probe data gives bad control. I compared manual control (not repeatable) against P that was too large (oscillation), too small (never reaches the set point) and a final tune with more integral term. As an appendix I tried Fourier analysis of roast audio to detect first crack, which I did not finish.
4. Shaders and atmospheric scattering. A way to improve my GPU programming, where pixels run in parallel and talking to the CPU is expensive, using Shadertoy's web-based GLSL editor. I started with short exercises: wave interference from summed sine waves, and a Mandelbrot set with complex math done through add and multiply helpers and logarithmic escape coloring. The main piece is atmospheric scattering based on the NVIDIA GPU Gems 2 chapter "Accurate Atmospheric Scattering". It marches along the view ray and sets each pixel's color from the light scattered out along the path and scattered in toward the camera, with a phase function and wavelength-dependent scattering coefficients. I also recreated the paper's optimization, compressing the double integral into precomputed optical depth values and cutting about 3000 calculations per pixel to 60. Both versions run at 60 fps, so it did not matter in practice (I forgot to save the optimized one).
What I learned: numerical methods for fluid mechanics, convolutions, the fast Fourier transform, PID and simple control theory, light transport equations, and how to write all of it so a computer can do the calculations. What I would change: focus on one topic, since each project could have been its own study, and spend less time on the roaster, which is a great engineering project but a stretch for math. The shaders were probably the most mathematical and the most fun.
| Role | Student project |
|---|---|
| Disciplines | Electrical/CS · Art |
| Tools | Python, NumPy, FFT convolution, GLSL, Shadertoy, PID control |
| Format | Departmental study, 4 projects |
| Fluids | Eulerian solver, pressure correction |
| Automata | Life, Smooth Life, Lenia (FFT convolution) |
| Control | PID loop in Artisan |
| Shaders | GLSL, atmospheric scattering, 60 fps |













