xxxxxxxxxx68
// Heres an example of an emergent behaviour! Abelian sand pit model creates complicated patterns from very simple rules// The canvas is divided into a grid of cells, each cell holds a certain number of sand grains.// if 4 sand grains are added to one cell the cell topples! It is reset to 0 grains and the grains move to neighbouring cells// this can trigger a chain reaction of toppling cells :) the model is symmetrical so adding grains to just one cell can create really neat patterns!// breaking the symmetry with just one or two random grains can completely break this! // Try it out! right click to fast add sand or left click to add grain at a time.// feel free to use this code as a boilerplate for your own project :)// -Euan Ripperlet cols = 100;//define the resolution of the displaylet rows = 100;let grid = [];//initialise a grid to store each celllet lastUpdate = [];let delayTime = 100;let cellSize = 6; bsp;//size of each cell allows for visual scalingfunction setup() {//initialise the display bsp;createCanvas(cols * cellSize, rows * cellSize);