colorMode(HSB,360,100,100,100);
size = gridsize * cellsize;
createCanvas((size * count) + ((count - 1) * padding) + border * 2, (size * count) + ((count - 1) * padding) + border * 2);
strokeWeight(cellsize / 10);
for (var y = 0; y < count; y++)
for (var x = 0; x < count; x++)
for (var i = 0; i < 10; i++)
snakes.push(new Snake(x * size + x * padding + border, y * size + y * padding + border));
rect(0,0,width,height,15);
for (var i = 0; i < snakes.length; i++) {
if (snakes[i].dead) snakes[i] = new Snake(snakes[i].x, snakes[i].y);
var segCount = random(1, 20);
var dir = p5.Vector.fromAngle(floor(random(10)) * (TWO_PI / 1)).mult(cellsize);
var pos = createVector(Math.ceil(random(size) / cellsize) * cellsize, Math.ceil(random(size) / cellsize) * cellsize);
var newPos = createVector(0, 0);
this.update = function() {
dir.rotate(random() < 0.9 ? -2 : 2);
newPos = p5.Vector.add(pos, dir);
if (segs.length > segCount) segs.pop();
var c = color(random(200, 240), random(1, 50), random(0, 100));
for (var i = 0; i < segs.length - 1; i++) {
if (s.x >= 0 && s.x <= size && s.y >= 0 && s.y <= size) {
if (e.x >= 0 && e.x <= size && e.y >= 0 && e.y <= size) {
line(s.x + this.x, s.y + this.y, e.x + this.x, e.y + this.y);
line(s.y + this.x, s.x + this.y, e.y + this.x, e.x + this.y);
line(size - s.x + this.x, s.y + this.y, size - e.x + this.x, e.y + this.y);
line(size - s.y + this.x, s.x + this.y, size - e.y + this.x, e.x + this.y);
line(s.x + this.x, size - s.y + this.y, e.x + this.x, size - e.y + this.y);
line(s.y + this.x, size - s.x + this.y, e.y + this.x, size - e.x + this.y);
line(size - s.x + this.x, size - s.y + this.y, size - e.x + this.x, size - e.y + this.y);
line(size - s.y + this.x, size - s.x + this.y, size - e.y + this.x, size - e.x + this.y);
rect(this.x, this.y, size, size, 5, 5, 5, 5);