In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

【高スペック推奨】ベロウソフ・ジャボチンスキー反応

重いのでシングルコアの方はご注意ください
たぶんgetPixel/SetPixelがよくないと思います
(1分ほどで渦縞模様が現れます)
Get Adobe Flash player
by kefir 18 Jan 2009
// write as3 code here..
// 
// 重いのでシングルコアの方はご注意ください
// たぶんgetPixel/SetPixelがよくないと思います
// (1分ほどで渦縞模様が現れます)
//
package {
  import flash.display.*
  import flash.events.*
  
  [SWF(width=100, height=100, backgroundColor=0x000000)]
  public class BZReaction extends Sprite
  {
    public function BZReaction():void {
        var bmd:BitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, true );
        var bmd_back:BitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, true );
        // このあたりの数値を変えるとパターンが変化します
        var max_state:Number = 150;
        var k1:Number = 3;
        var k2:Number = 3;
        var g:Number = 24;
        addChild( new Bitmap(bmd) );
        bmd.noise(1, 0, max_state, 1, false);
        stage.addEventListener( Event.ENTER_FRAME, function( e:Event ):void {
        for( var i:Number = 0; i < stage.stageWidth; ++ i ) {
          for( var j:Number = 0; j < stage.stageHeight; ++ j ) {
            function getState( di:Number, dj:Number ): Number {
              return bmd.getPixel( (i + di) % stage.stageWidth, (j + dj) % stage.stageHeight) >> 16
            }
            function sum_of_neighbors( f ): Number {
                return f(-1, -1) + f(-1, 0) + f(-1, 1) + f(0, -1) + f(0, 1) + f(1, -1) + f(1, 0) + f(1, 1)
            }
            var state:Number = bmd.getPixel(i, j) >> 16;
            var new_state:Number;
            if( state >= max_state )
            {
              new_state = 0;
            }
            else
            {
              ( function(a:Number, b:Number, c:Number) {
                new_state = ( state == 0 ) ? int(a / k1) + int(b / k2): c / (a + b + 1) + g;
                if ( new_state > max_state ) new_state = max_state;
              } )( 
                sum_of_neighbors( function( di:Number, dj:Number ): Boolean { 
                  return function( i:Number ){ return ( i > 0 && i < max_state ) 
                }( getState(di, dj) ) } ), 
                sum_of_neighbors( function( di:Number, dj:Number ): Boolean { 
                  return getState(di, dj) == max_state 
                } ), 
                sum_of_neighbors( getState ) + state 
              )
            }
            bmd_back.setPixel( i, j, new_state << 16 );
          } // j
        } // i
        bmd.draw(bmd_back);
      } )
    } // public function BZReaction
  } // public class BZReaction
} // package