Visualizes expectations as integrals under a target distribution p(x), then approximates E_p[f(X)] with Monte Carlo averages. The animation alternates between direct sampling (X~p) and importance sampling (X~q with weights p/q), while a live error panel shows the characteristic 1/√N accuracy scaling and how variance controls estimator noise.
Pure Canvas2D. Uses a closure to maintain sample state and running variance (Welford). Densities are drawn on [-1,1] with block-snapped geometry for a retro grid aesthetic; samples accumulate over time and the estimator/error panels update each frame. The “true” expectation is approximated via dense quadrature for a stable reference.