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

Simulating Belousov–Zhabotinsky Reactions in Flex

DZone's Guide to

Simulating Belousov–Zhabotinsky Reactions in Flex

· Web Dev Zone ·
Free Resource

Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.

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.

Monitor application stability with Bugsnag to decide if your engineering team should be building new features on your roadmap or fixing bugs to stabilize your application.Try it free.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}