Water Ripple Effect. Simulation in C++ ImGui

Markus Buchholz
2 min readMar 27, 2023

The ripple effect arises when the local disturbance in the system propagates across the system and affects an increasingly more significant part of the whole system. The process is often associated with the ripples expanding in the water when the external object falls (disturbs) the water's surface.
This article was inspired by a remarkable YT channel by Daniel Shiffman. The intention was to simulate the disturbances of the water. The algorithm is presented here.

The main idea of the algorithm can be depicted as follows.
There are two matrices that hold the numerical float value. Matrices are initialized to null since they reflect later the black color. In my case, the value of each position of the matrix determines the color of the pixel on the screen. Both matrices are considered as current and previous states of the system (screen).
In the simulation, I do not use the matrices operation from Eigen library but I construct matrices as a two-dimensional vector.
In each step of the simulation, the value of each pixel (which determines the color on the screen) is calculated as follows (see below figure).
Please note the figure displays only principles which are slightly adjusted in the C++ code.

Computation of new value of pixel (position in the matrix). (by author)

After updating each pixel of the current matrix, displayed on the screen, the current matrix has to be swapped with the previous one. I applied the swap algorithm which in my case performs a swap operation of two unique pointers.

The simulation can be run in two different scenarios (regulated by flagX) Random drops and drops initialized by mouse movement modus are available.

Random drops (by author)
Disrrubance initialized by mouse movement (by author)

The implementation of the solution I deployed in C++ with the visualization in ImGui. The introduction to the C++ ImGui and information on how to compile and build programs you will find in one of my previous articles.

The source code you will find on my GitHub.

Thank you for reading.

--

--