Ripples
Ripples spread across a surface, bounce off the edges and overlap. A stylized wave model.
Published
No video preview yet
Source
use "@hyle/maths";
// Each vertical column carries the same surface-wave state. Height is revealed
// by voxel opacity; this is a height field, not a three-dimensional fluid solver.
const coupling: Float = 0.16;
const damping: Float = 0.995;
const restingHeight: Float = 6.0;
const heightGain: Float = 12.0;
property Wave {
displacement: Float = 0.0;
velocity: Float = 0.0;
layer: Float [0.0, 13.0] = 0.0;
}
property Solid { density: Float = 1.0; }
model TidalCrest : Wave { displacement = 0.85; };
model Pool : Wave;
model Obsidian : Solid;
world { dimensions = 3; neighborhood = VonNeumann; }
// Identical vertical samples contribute zero curvature. Horizontal neighbors
// propagate the ripples, and missing edge neighbors reflect them back inward.
behavior WaveAcceleration for Wave {
update {
let laplace = sum n in neighbors[Wave] { n.displacement - self.displacement };
set self.velocity = maths::clip((self.velocity + laplace * coupling) * damping, -0.5, 0.5);
}
}
// Separate phases let every column integrate the newly computed velocity.
behavior WaveIntegration for Wave {
update { set self.displacement = maths::clip(self.displacement + self.velocity, -1.0, 1.0); }
}
phase acceleration { run WaveAcceleration on TidalCrest; run WaveAcceleration on Pool; }
phase integration { run WaveIntegration on TidalCrest; run WaveIntegration on Pool; }
visual NeonWater for Wave {
color {
let height = maths::clip(restingHeight + self.displacement * heightGain, 1.0, 13.0);
// Empty samples remain in the solver so a trough can rise again. Fractional
// opacity softens the top voxel without changing the wave's state.
let depth = height - self.layer;
let fill = maths::clip(depth, 0.0, 1.0);
// Only the surface needs neon color. Buried and invisible samples keep
// stable RGB values, avoiding unnecessary preview/timeline color deltas.
let surface = fill * maths::clip(2.0 - depth, 0.0, 1.0);
let lift = maths::clip(self.displacement * 4.0, -1.0, 1.0) * surface;
rgba(0.20 + maths::maximum(lift, 0.0) * 0.75,
0.40 + maths::maximum(-lift, 0.0) * 0.58,
0.85 - maths::maximum(lift, 0.0) * 0.30, fill)
}
}
visual DarkBase for Solid { color { rgba(0.07, 0.09, 0.14, 1.0) } }
visualize TidalCrest with NeonWater;
visualize Pool with NeonWater;
visualize Obsidian with DarkBase;