Playground

Write a streamfunction

The animation on my front page isn't a picture — it's a few thousand tracer particles drifting along the streamlines of a flow you can rewrite yourself.

ψ(X, Y, T) = edit me — the picture follows along

 

 

What you're looking at

A two-dimensional incompressible flow can be written entirely in terms of a single scalar function, the streamfunction $\psi$. The velocity comes from its derivatives:

$$u=\frac{\partial\psi}{\partial Y},\qquad v=-\frac{\partial\psi}{\partial X}$$

Take the divergence of that and the cross-derivatives cancel identically, so $\nabla\cdot\mathbf{u}=0$ no matter what $\psi$ you pick. Mass is conserved by construction — the tracers never bunch up or thin out, and the curves they trace are contours of $\psi$ itself.

The page differentiates whatever you type numerically, by central differences, so you can write any expression you like without working out the derivatives by hand. Every particle just reads the local velocity, takes a small step, and leaves a fading trail.

What you can write

Variables

X, Y — position, centred on the canvas (X runs about ±3.5, Y about ±1.5)
T — time, climbing slowly
PI, E, TAU

Operators

+ - * / % ^ and parentheses

Functions

sin cos tan asin acos atan sinh cosh tanh exp log log2 log10 sqrt abs sign floor ceil round and the two-argument atan2 pow hypot min max mod

Things worth trying

  • Multiply two sines — sin(X)*sin(Y) — and you get a lattice of counter-rotating cells. That one is an exact solution of the Navier–Stokes equations.
  • Add + 0.3*T inside a sine to set the whole pattern drifting.
  • log(cosh(Y)) alone gives a clean tanh shear layer; add a small travelling bump and watch it try to roll up.
  • log(hypot(X, Y) + 0.2) is a single point vortex. Subtract a second one somewhere else to make a dipole.
  • Anything with a large coefficient turns into fine-grained chaos — which is its own kind of fun.

A note on safety

Whatever you type is read by a small mathematical parser written for this page — it understands numbers, the variables above, arithmetic, and that list of functions, and nothing else. It never calls eval. There is no way to express anything but a number, which is why sharing a field by link is harmless: the worst a stranger can send you is an ugly picture.

← Back to all projects