css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              var dimx = 256;
var dimy = dimx;

var field = new field2D(dimx, dimy);
var past = new field2D(dimx, dimy);

// @see http://www.sciencedirect.com/science/article/pii/016727898990081X#
// This typically goes through several stages:
// first a mass pulsing, more or less synchronized with a textured brain-like pattern
//) { circular pulsing pockets begin to appear and grow, with waves pushing to larger regions at different phases
//) { spiral patterns begin to appear and overcome the still growing pulsations
// the spirals break down under their own advection into smaller spirals while the bigger waves consume the remaining space
// the crucial parameter to vary these behaviors is sickness_rate
var sickness_rate = 0.11;
var infection_rate_infected = 1 / 3;
var infection_rate_ill = 1;
var initial_infection = 1 / 255;

function initialize() {
  return 1 - random() * random()


// how to r}er the scene
function draw(ctx) {
  // draw the field (by default it fills the canvas):

// a cell is infected if (the value is greater than zero:
var isinfected = Math.ceil;
// a cell is ill if (the value is equal or greater than 1:
var isill = Math.floor;

var floor = Math.floor;
var min = Math.min;

// the rule for an individual cell (at position x, y) in the field:
function transition(x, y) {

  // check my own previous state:
  var C = past.get(x, y);

  // check out the neighbors' previous states:
  var N = past.get(x, y + 1);
  var NE = past.get(x + 1, y + 1);
  var E = past.get(x + 1, y);
  var SE = past.get(x + 1, y - 1);
  var S = past.get(x, y - 1);
  var SW = past.get(x - 1, y - 1);
  var W = past.get(x - 1, y);
  var NW = past.get(x - 1, y + 1);

  if (C >= 1) {
    // all ill cells are healed automatically:
    C = 0;
  } else if (C > 0) {
    // infected
    var nearbyinfection = C + N + NE + E + SE + S + SW + W + NW;
    var nearbyinfected = 1 + isinfected(N) + isinfected(NE) + isinfected(E) + isinfected(SE) + isinfected(S) + isinfected(SW) + isinfected(W) + isinfected(NW);
    var averageinfection = nearbyinfection / nearbyinfected;
    C = sickness_rate + averageinfection;
    C = min(1, C);
  } else {
    // healthy cell:

    // number of var infected:
    var nearbyinfected = (
      isinfected(N) + isinfected(NE) + isinfected(E) + isinfected(SE) + isinfected(S) + isinfected(SW) + isinfected(W) + isinfected(NW)
    // calculate number of var ill:
    var nearbyill = (
      isill(N) + isill(NE) + isill(E) + isill(SE) + isill(S) + isill(SW) + isill(W) + isill(NW)

    var influence = floor(nearbyinfected * infection_rate_infected) + floor(nearbyill * infection_rate_ill);

    C = initial_infection * influence;
  // a sick cell gets sicker by a fixed amount, plus extra sickness due to infected neighbours. It cannot get sicker than the limit.
  // An uninfected cell may catch infection, depending on its neighbours.
  // At the next 'tick' any ill cells are healed!

  // return the new state:
  return C;

function update() {
  var tmp = past;
  past = field;
  field = tmp;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................