A body immersed in a fluid feels an upward force equal to the weight of the fluid it displaces (Archimedes): Fb = ρf g Vsub. A cube of side s and density ρo floats with draft d = (ρo/ρf) s and sinks if ρo > ρf.
The vertical motion is integrated every 1/1200 s from (m + ma) dv/dt = Fb - mg - ½ρf CD A |v| v - Frad, with a cube drag coefficient CD = 1.05, an added mass ma = 0.63 ρf V (scaled by the wetted fraction) and, only while the surface pierces the cube, a heave damping ratio ζ = 0.12 standing in for wave radiation. The water level follows mass conservation: L = L0 + Vsub/A, solved self-consistently because Vsub depends on L.
The checks compare the integrator with closed forms: equilibrium draft in four fluids, level rise V/A, a no-drag heave period 2π√((m + ma)/k) with k = ρf g s²(1 - s²/A), the tanh approach to terminal speed, and the settled force balance.
Simplifications: only vertical motion is simulated; cubes are rigid, never tip or rotate (a real light cube can be unstable on a face) and are only pushed apart horizontally; no surface tension, waves or sloshing; the damping ratio and added-mass coefficient are textbook-size estimates, not measurements; the water top is flat. The tank is 50 x 50 x 40 cm, so an 8 cm cube displaces at most 512 mL.
Running numerical checks...