Conveyor Belt in Cellular Automata

c

var canvas = document.getElementById("canvas");
var canvas = document.getElementById("canvas"); 
var ctx = canvas.getContext("2d"); 
var img; var current, prev, imageData;

function RunOnce()  
{ 
   for (var y = 1; y < img.height - 1; ++y) 
   { 
      for (var x = 1; x < img.width - 1; ++x)
      { 
          var n = (y * img.width + x) * 4; // pixel address 
          var c = prev[n]; // color var neighbours = 0; 
          for (var a = -1; a < 2; ++a) 
              for (var b = -1; b < 2; ++b) 
                 if (!(a == 0 && b == 0) && prev[((y + b) * img.width + (x + a)) * 4] == 240) 
                     neighbours++; 

          if (c == 240 && neighbours >= 3 && neighbours <= 5) 
              continue; 

          if (c >= 80) 
              current[n] = c - 80; 
          else 
              current[n] = neighbours == 2 ? 240 : 0; 
       } 
    } 

    ctx.putImageData(imageData, 0, 0); 
    prev.set(current);  
    setTimeout(function() { RunOnce(); }, 10); 
}

function loadImageFromFile(event)
{
    document.getElementById("label").style.visibility = "hidden";
    var reader = new FileReader();
    img = document.getElementById("world");
    reader.onload = function(event) 
    {
       img.onload = function() 
       { 
           ctx.drawImage(img, 0, 0); 
           imageData = ctx.getImageData(0, 0, img.width, img.height);
           current = imageData.data;
           prev = new Uint8ClampedArray(imageData.data);
           RunOnce();
       };
       img.src = event.target.result;
    } 
    reader.readAsDataURL(event.target.files[0]);
}
conveyor

Source image for conveyor belt example. Should be in 24bit bmp format

glider_gun

Source image for glider gun

burning_arrow

Source image for burning arow

 

Strange Attractors

attractor

var canvas = document.getElementById("canvas"); 
var ctx = canvas.getContext("2d"); 
var width = 800; 
var height = 800; 
var pixels = Array(width).fill(0).map(x => Array(height).fill(0.0)); 

//var a = -1.4, b = 1.6, c = 1.0, d = 0.7; 
//var a = 1.7, b = 1.7, c = 0.6, d = 1.2; 
//var a = -1.8, b = -2.0, c = -0.5, d = -0.9; 
var a = -1.4, b = 1.6, c = -1.0, d = 0.9; 
//var a = 1.5, b = -1.8, c = 1.6, d = 0.9; 

var x = 0, y = 0; 
var max = 0.0; 

// generate 
for (var i = 0; i < 40000000; ++i) 
{ 
   var x1 = Math.sin(a * y) + c * Math.cos(a * x); 
   var y1 = Math.sin(b * x) + d * Math.cos(b * y); 

   var m = Math.round((x1 + 2.5) * width / 5); 
   var n = Math.round((2.5 - y1) * height / 5); 
   var h = ++pixels[m][n]; 
   max = Math.max(max, h); 

   x = x1; 
   y = y1; 
} 

// draw 
for (var m = 0; m < width; ++m) 
{ 
   for (var n = 0; n < height; ++n) 
   { 
       var color = 2 * Math.round(Math.sqrt(pixels[m][n] / max) * 100.0); 
       color = Math.max(0, Math.min(color, 100)); 
       ctx.fillStyle = "hsl("+ 30 + "," + 100 + "%," + (100 - color) +"%)"; 
       ctx.fillRect(m, n, 1, 1); 
   } 
}

A Bunch of Dragon Flowers

Capture

var canvas = document.getElementById("canvas"); 
var ctx = canvas.getContext("2d"); 

for (var x = 0; x < 1000; ++x) 
{ 
   for (var y = 0; y < 600; ++y) 
   { 
       var c = -0.835, ci = -0.2321; 
       var z = x / 300.0 - 1.7; 
       var zi = y / 300.0 - 1; 

       for (var i = 255; i > 0; --i) 
       { 
           var a = z * z - zi * zi + c; 
           var b = 2 * z * zi + ci; 
           if (a * a + b * b > 50) 
           { 
               ctx.fillStyle = "rgb("+ i + "," + i + "," + 255 +")"; 
               ctx.fillRect(x, y, 1, 1); 
               break; 
           } 
           z = a; 
           zi = b; 
       } 
    } 
}

 

බීමට වැහි වතුර

ඉස්සර අපි වැව් වතුර බිව්වේ. ඒත් දැන් වතුරේ ආසනික්. ඒ නිසා පුද්ගලික වැව් හදාගන්න වෙලා. සාමූහිකත්වයෙන් පුද්ගලිකත්වයට මාරුවෙලා.

123

4

අඟුරු-වැලි පෙරනය

5