• fullscreen
  • bzr.pde
  • // Idealised Belousov–Zhabotinsky reaction
    // (c) Alasdair Turner 2009
    // Free Software
    // Licensed according to the GNU GPL
    
    // An implementation note about this algorithm is available here:
    // http://www.aac.bartlett.ucl.ac.uk/processing/samples/bzr.pdf
    
    float [][][] a;
    float [][][] b;
    float [][][] c;
    
    int p = 0, q = 1;
    
    void setup()
    {
      size(400,400);
      colorMode(HSB,1.0);
      a = new float [width][height][2];
      b = new float [width][height][2];
      c = new float [width][height][2];
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          a[x][y][p] = random(0.0,1.0);
          b[x][y][p] = random(0.0,1.0);
          c[x][y][p] = random(0.0,1.0);
          set(x,y,color(0.5,0.7,a[x][y][p]));
        }
      }
    }
    
    void draw()
    {
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          float c_a = 0.0;
          float c_b = 0.0;
          float c_c = 0.0;
          for (int i = x - 1; i <= x+1; i++) {
            for (int j = y - 1; j <= y+1; j++) {
              c_a += a[(i+width)%width][(j+height)%height][p];
              c_b += b[(i+width)%width][(j+height)%height][p];
              c_c += c[(i+width)%width][(j+height)%height][p];
            }
          }
          c_a /= 9.0;
          c_b /= 9.0;
          c_c /= 9.0;
          // adjust these values to alter behaviour
          a[x][y][q] = constrain(c_a + c_a * (c_b - c_c), 0, 1);
          b[x][y][q] = constrain(c_b + c_b * (c_c - c_a), 0, 1);
          c[x][y][q] = constrain(c_c + c_c * (c_a - c_b), 0, 1);
          set(x,y,color(0.5,0.7,a[x][y][q]));
        }
      }
      if (p == 0) {
        p = 1; q = 0;
      }
      else {
        p = 0; q = 1;
      }
    }
    
    

    code

    tweaks (1)

    license

    advertisement

    Report Sketch

    Report for inappropriate content

    Please provide details if possible:

    Your have successfully reported the sketch. Thank you very much for helping to keep OpenProcessing clean and tidy :)

    Make a Copyright Infringement claim

    Alasdair Turner

    BZ reaction

    Add to Faves Me Likey@! 59
    You must login/register to add this sketch to your favorites.

    This is a dynamic equilibrium equation for cellular automata which works on the principle of a Belousov-Zhabotinsky-like reaction. To make how it works clearer, I have separated the CA values into three concentrations of components 'a', 'b' and 'c'.

    I have written a short implementation note for further details available here:

    <a href="http://www.aac.bartlett.ucl.ac.uk/processing/samples/bzr.pdf">BZ reaction implementation note (pdf)</a>

    This is very cool - thanks for posting it!
    Alasdair Turner
    22 Mar 2009
    I'm glad you like it! If you like patterns from nature, Philip Ball has a new trilogy of books coming out: "Shapes", "Branches" and "Flow", and of course take a look at Processing virtuoso Dan Shiffman's Nature of Code http://www.shiffman.net/teaching/nature/
    Starkes
    11 May 2009
    pimp!
    Xiaohan Zhang
    20 May 2009
    wow! that looks amazing. and such little code!
    lifo fernandez
    3 Aug 2009
    oh yes its very little, ive realised just now.
    awesome.
    Philip Sharman
    16 Jul 2016
    For anyone else looking, the location of the PDF now seems to be here:
    http://discovery.ucl.ac.uk/17241/1/17241.pdf.
    Philip Sharman
    16 Jul 2016
    For anyone else looking, the location of the PDF now seems to be here:
    http://discovery.ucl.ac.uk/17241/1/17241.pdf.
    You need to login/register to comment.