snake.push(new snake_tile(100, 100, 10));
target = createVector(random(800 - 10), random(600 - 10));
rect(target.x, target.y, 20);
for (let t = 0; t < snake.length; t++) {
if (last.pos.dist(target) > 10) {
let next = find_next(last, target);
snake.push(new snake_tile(next.x, next.y, 10));
target = createVector(random(800 - 10), random(600 - 10));
function find_next(tile, target) {
if (tile.pos.x >= 0 && tile.pos.x <= 800) {
if (tile.pos.x >= target.x) {
if (tile.pos.y >= 0 && tile.pos.y <= 600) {
if (tile.pos.y >= target.y) {
this.pos = createVector(x, y);
this.c = color(255, 255, 63);
this.ttl = Math.max(this.ttl - 1, 0);
let life = map(this.ttl, 0, 30, 0, 1);
let nc = lerpColor(color(0, 0), this.c, life);
ellipse(this.pos.x, this.pos.y, this.size);
ellipse(this.pos.x + 10, this.pos.y, this.size);
ellipse(this.pos.x - 10, this.pos.y, this.size);
ellipse(this.pos.x, this.pos.y + 10, this.size);
ellipse(this.pos.x, this.pos.y - 10, this.size);