var neighbourGrowth = 55;
var infectionChanceColour = 97;
var infectionChanceOrientation = 97;
var nrOfChecksAllowed = 1;
var colour1 = new Array(255, 0, 0);
var colour2 = new Array(100, 150, 255);
var backgroundColour = new Array(21, 13, 0);
var embroideryThickness = 4;
background(backgroundColour[0], backgroundColour[1], backgroundColour[2]);
columns = floor(width/gridSize);
rows = floor(height/gridSize);
nrOfSectors = columns*rows;
background(backgroundColour[0], backgroundColour[1], backgroundColour[2]);
function initialiseSectors() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < columns; x++) {
sectors[index] = new Sector(x*gridSize, y*gridSize, index, 0, 0, 0);
for (let i = 0; i < nrOfSeeds; i++) {
let seedNumber = int(random(nrOfSectors));
sectors[seedNumber].determineActivation(int(random(RED, BLUE+1)), int(random(RED, BLUE+1)));
sectors[seedNumber].show();
for (let y = 0; y <= rows; y++) {
for (let x = 0; x <= columns; x++) {
ellipse(x*gridSize, y*gridSize, holeSize, holeSize);
function growStitches() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < columns; x++) {
if ((sectors[index].leftLine != 0 || sectors[index].rightLine != 0) && sectors[index].checks < nrOfChecksAllowed) {
if (index < (nrOfSectors - 1) && (index % rows != (columns - 1))) {
let chance = int(random(100));
if (chance < neighbourGrowth) {
sectors[index+1].determineActivation(sectors[index].leftLine, sectors[index].rightLine);
if (index != 0 && (index % rows != 0)) {
let chance = int(random(100));
if (chance < neighbourGrowth) {
sectors[index-1].determineActivation(sectors[index].leftLine, sectors[index].rightLine);
let chance = int(random(100));
if (chance < neighbourGrowth) {
sectors[index-columns].determineActivation(sectors[index].leftLine, sectors[index].rightLine);
if (index < (nrOfSectors - columns)) {
let chance = int(random(100));
if (chance < neighbourGrowth) {
sectors[index+columns].determineActivation(sectors[index].leftLine, sectors[index].rightLine);
constructor(x, y, n, checks, leftLine, rightLine){
this.leftLine = leftLine;
this.rightLine = rightLine;
determineActivation(leftLine_, rightLine_) {
this.determineInheritanceLeft(leftLine_);
this.determineInheritanceRight(rightLine_);
determineInheritanceLeft(leftLine_) {
let orientationChance = int(random(100));
if (orientationChance < infectionChanceOrientation) {
this.leftLine = this.determineColour(leftLine_);
this.rightLine = this.determineColour(leftLine_);
determineInheritanceRight(rightLine_) {
let orientationChance = int(random(100));
if (orientationChance < infectionChanceOrientation) {
this.rightLine = this.determineColour(rightLine_);
this.leftLine = this.determineColour(rightLine_);
determineColour(inputLine_) {
let colourChance = int(random(100));
if (colourChance < infectionChanceColour) {
} else if (inputLine_ == BLUE) {
if (colourChance < infectionChanceColour) {
strokeWeight(embroideryThickness);
if (this.leftLine == RED) {
stroke(colour1[0], colour1[1], colour1[2]);
line(this.posX, this.posY, this.posX + gridSize, this.posY + gridSize);
} else if (this.leftLine == BLUE) {
stroke(colour2[0], colour2[1], colour2[2]);
line(this.posX, this.posY, this.posX + gridSize, this.posY + gridSize);
if (this.rightLine == RED) {
stroke(colour1[0], colour1[1], colour1[2]);
line(this.posX + gridSize, this.posY, this.posX, this.posY + gridSize);
} else if (this.rightLine == BLUE) {
stroke(colour2[0], colour2[1], colour2[2]);
line(this.posX + gridSize, this.posY, this.posX, this.posY + gridSize);