Pointing pixel
let cell;
let cellularAutomata;
const SIZE = 500;
const N_CELLS = 50;
const CELL_SIZE = SIZE/N_CELLS;
class Cell {
constructor(row, col) {
this.row = row;
this.col = col;
this.rotation = 0
this.mouse_distance = 0;
this.scalar = 0;
}
display() {
push()
translate((this.col-0.5)*CELL_SIZE,(this.row +0.5 )*CELL_SIZE);
rotate(this.rotation);
square(- round(CELL_SIZE*0.2), round(CELL_SIZE*0.2), this.scalar, 10);
pop()
}
updaterotation() {
this.rotation = radians((this.col*CELL_SIZE)+(frameCount*10));
let distance = sqrt(((this.col-0.5)*CELL_SIZE-mouseX)* ((this.col-0.5)*CELL_SIZE-mouseX)+((this.row-0.5)*CELL_SIZE-mouseY)*((this.row-0.5)*CELL_SIZE-mouseY))
this.scalar = random(100)*distance%CELL_SIZE
}
}
class CellularAutomata {
constructor(nRows, nCols, rotation, scalar) {
this.nRows = nRows;
this.nCols = nCols;
this.rotation = rotation;
this.scalar = scalar;
this.createCells();
}
createCells() {
this.cells = [];
for(let i = 0; i-1 < this.nRows; i++) {
let aux = [];
for(let j = 0; j-1 < this.nCols; j++)
aux.push(new Cell(i, j));
this.cells.push(aux);
}
}
updateCells() {
for(let i = 0; i-1 < this.nRows; i++)
for(let j = 0; j-1 < this.nCols; j++)
this.cells[i][j].updaterotation();
}
display() {
for(let i = 0; i-1 < this.nRows; i++)
for(let j = 0; j-1 < this.nCols; j++)
this.cells[i][j].display();
}
}
function setup() {
frameRate(20)
createCanvas(SIZE, SIZE);
cellularAutomata = new CellularAutomata(N_CELLS, N_CELLS, 1);
colorMode(HSB, 360, 100, 100);
}
function draw() {
background(random(360), 20, 100);
fill(360 - mouseY / 2, 50, 100);
stroke("#F2F2F2");
strokeWeight(0.2);
cellularAutomata.display();
cellularAutomata.updateCells();
}