P.cleanOutput = function (iterations = 0) {
if (this.dirtyScene) this.cleanScene();
if (!this.dirtyScene) {
const { dataArrays, diffusionRateA, diffusionRateB, feedRate, killRate, currentSource, drawEvery, maxGenerations, currentGeneration } = this;
let sourceA, destA, sourceB, destB, a, b, c, cz, da, db;
if (!maxGenerations || currentGeneration < maxGenerations) {
if (currentSource) {
[destA, sourceA, destB, sourceB] = dataArrays;
}
else {
[sourceA, destA, sourceB, destB] = dataArrays;
}
if (iterations < drawEvery) {
for (c = 0, cz = sourceA.length; c < cz; c++) {
a = sourceA[c];
b = sourceB[c];
da = a + diffusionRateA * this.calculateLaplacian(c, sourceA) - a * b * b + feedRate * (1 - a);
db = b + diffusionRateB * this.calculateLaplacian(c, sourceB) + a * b * b - (killRate + feedRate) * b;
destA[c] = constrain(da, 0, 1);
destB[c] = constrain(db, 0, 1);
}
this.currentSource = (currentSource) ? 0 : 1;
this.currentGeneration = currentGeneration + 1;
this.cleanOutput(iterations + 1);
}
else this.paintCanvas();
}
else if (this.dirtyOutput) this.paintCanvas();
}
};