Simulating Belousov-Zhabotinsky Reaction in Houdini
Do you remember when complex video simulations of scientific concepts was difficult? Look what you can do with 13 lines of code today.
Join the DZone community and get the full member experience.Join For Free
The Belousov-Zhabotinsky reaction is an amazing looking chemical reaction that can be simulated with some pretty simple maths. I've written about it several times and recreated it in several technologies. As part of my "running before I can walk" dive into Houdini, I've implemented the simulation in VEX.
First things first, a few important acknowledgments: VEX in Houdini and this tutorial from Entagma on creating Mandelbrot sets in Houdini got me up and running with Point Wrangle nodes and cgwiki which is an awesome repository of technical Houdini wizardry that I've been jumping to all day.
The project is pretty simple: I have a grid geometry to which I add a Solver geometry node. The solver allows for iteration: it contains a "previous frame" Dop Import node which allows me to use the values from the previous frame inside a VEX expression. To the previous frame node, I add a Point Wrangle containing the Belousov maths. This requires values for three chemicals and for those, I use to red, green and blue values of each point.
Part of the equation is to get the average of the neighboring cells and to do this, I use pcopen() and pcfilter()(thanks again to cgwiki!). The final VEX is:
float alpha = 1.45; float beta = 1.75; float gamma = 1.55; int pointCloud = pcopen(0, 'P', @P, 1, 8); vector averageColor = pcfilter(pointCloud, 'Cd'); float a = averageColor.x + averageColor.x * (alpha * gamma * averageColor.y) - averageColor.z; float b = averageColor.y + averageColor.y * ((beta * averageColor.z) - (alpha * averageColor.x)); float c = averageColor.z + averageColor.z * ((gamma * averageColor.x) - (beta * averageColor.y)); @Cd = set(clamp(a, 0, 1), clamp(b, 0, 1), clamp(c, 0, 1)); @P.y = c * 0.08;
The last two lines of code update the current point's color to the new red, green and blue values and displace each point based on the value of blue.
Published at DZone with permission of Simon Gladman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.