const turnProbability = 0.125;
const step = (width - padding * 2) / cellCount;
const spacing = step - cellSize;
for (let y = padding; y < height - padding; y += step) {
for (let x = padding; x < width - padding; x += step) {
cellArray.push(new Cell(x + step / 2, y + step / 2));
colorMode(HSB, 360, 100, 100, 100);
rect(0, 0, width, height, 30);
for (const cell of cellArray) {
const x = int(random(-cellSize / 2, cellSize / 2));
const y = int(random(-cellSize / 2, cellSize / 2));
const pos = createVector(x, y);
this.color = color(random(360), random(10, 70), 100);
this.dir = createVector(1, 0).rotate(random(PI * 2));
if (random(1) < turnProbability) {
const head = this.list[0].copy();
head.add(this.dir.copy().mult(step));
if (abs(head.x) > cellSize / 2 || abs(head.y) > cellSize / 2) {
if (this.list.length > snakeLength) {
pos=> pos.copy().rotate(TWO_PI / 3),
pos=> pos.copy().rotate((TWO_PI / 3) * 2),
pos=>createVector(pos.x, -pos.y),
pos=>createVector(pos.x, -pos.y).rotate(TWO_PI / 3),
pos=>createVector(pos.x, -pos.y).rotate((TWO_PI / 3) * 2),
for (const func of symmetry6) {
for (const part of this.list) {
const { x, y } = func(part).rotate(angle);
this.angle = random(TWO_PI);
while (this.snakes.length < snakesNum) {
this.snakes.push(new Snake());
for (const snake of this.snakes) {
const distance = dist(mouseX, mouseY, this.x, this.y);
this.angle += 1 / max(0.1, distance);
for (const snake of this.snakes) {
this.snakes = this.snakes.filter((snake) => snake.isDead === false);
translate(this.x, this.y);
for (const snake of this.snakes) {