Over a million developers have joined DZone.

Simulating Belousov–Zhabotinsky Reactions in Flex

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

The Belousov-Zhabotinsky (BZ) reaction is a class of chemical reaction that exhibits morphogenesis or spontaneous pattern creation. The mechanism by which it generates patterns is known as reaction-diffusion and was actually separately proposed by Alan Turing in his famous paper, "The Chemical Basis of Morphogenesis".

I stumbled across this paper written by Alasdair Turner. He wrote some code for Processing to simulate the reaction, so I spent a little time this morning porting it to ActionScript and giving it a UI.

The initial condition is a randomised and homogenous mix of values. As the simulation runs, typical BZ spirals and circles appear - this is morphogenesis.

I've added horizontal sliders to tweak the rate of reaction between the different substrates in the reaction. Subtle variations in these rates can change the patterns between circles and spirals and have can get the entire virtual petri dish oscillating.

I've also added false color rendering to the output. The values from the BZ solver range from 0 to 1, my code gets the colour value from a linear gradient based on the reaction value in each cell. The list on the left has a handful of gradients that can be selected.

The code itself is pretty simple - with the exception of an item renderer for the gradients in the list, all the code sits in the main application MXML file. However, it's doing a lot of work each frame and isn't fast.

Does this code simulate 'real reactions? Belousov himself had problems trying to publish his work because he couldn't really explain his findings and there was some disbelief the reaction existed at all. However, there are plenty of examples on YouTube of BZ spirals appearing out of chemical reactions.




The application lives here and the source code is available here.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}