Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# 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.

· Mobile Zone
Free Resource

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

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.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
visualization ,graphics ,scientific computing

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Published at DZone with permission of Simon Gladman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.