xxxxxxxxxx
82
/*
----- Coding Tutorial by Patt Vira -----
Name: NileRed Logo (BZ Reaction)
Video Tutorial: https://youtu.be/CicXI-WBgQ4
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let a = [], b = [], c = [];
let cols, rows; let size = 4;
let p = 0, q = 1;
let alfa = 1.2, beta = 1.0, gamma = 1.0;
function setup() {
createCanvas(400, 400);
cols = width/size;
rows = height/size;
for (let x=0; x<cols; x++) {
a[x] = [];
b[x] = [];
c[x] = [];
for (let y=0; y<rows; y++) {
a[x][y] = [random(0, 1), random(0, 1)];
b[x][y] = [random(0, 1), random(0, 1)];
c[x][y] = [random(0, 1), random(0, 1)];
}
}
}
function draw() {
background(220);
for (let x=0; x<cols; x++) {
for (let y=0; y<rows; y++) {
let c_a = 0.0;
let c_b = 0.0;
let c_c = 0.0;
for (let i=x-1; i<=x+1; i++) {
for (let j=y-1; j<=y+1; j++) {
let xIndex = (i + cols) % cols;
let yIndex = (j + rows) % rows;
c_a += a[xIndex][yIndex][p];
c_b += b[xIndex][yIndex][p];
c_c += c[xIndex][yIndex][p];
}
}
c_a /= 9.0;
c_b /= 9.0;
c_c /= 9.0;
a[x][y][q] = constrain(c_a + c_a * (alfa * c_b - gamma * c_c), 0, 1);
b[x][y][q] = constrain(c_b + c_b * (beta * c_c - alfa * c_a), 0, 1);
c[x][y][q] = constrain(c_c + c_c * (gamma * c_a - beta * c_b), 0, 1);
}
}
[p, q] = [q, p];
for (let x=0; x<cols; x++) {
for (let y=0; y<rows; y++) {
noStroke();
let val = a[x][y][p];
let r = lerp(255, 150, val);
let g = lerp(100, 210, val);
let b = lerp(0, 255, val);
fill(r, g, b);
rect(x*size, y*size, size, size);
}
}
}