let cols, rows, bgCol, elemCol, sideMargin, verMargin;
let centers = [], rects = [], tiles = [], letters = [];
let maxR = 200; let minR = 60;
let maxG = 140; let minG = 40;
let maxB = 120; let minB = 30;
let action1 = false, action2 = false, action3 = false, action4 = false, action5 = false;
myFont = loadFont('PressStart.otf');
createCanvas(innerWidth, innerHeight);
elemCol = color(187, 184, 169);
cols = int( width / gridSize );
rows = int( height / gridSize );
sideMargin = (innerWidth - (cols * gridSize)) /2;
verMargin = (innerHeight - (rows * gridSize)) /2;
translate(gridSize/2, gridSize/2);
for (let v = 0; v < cols; v++) {
for (let r = 0; r < rows; r++) {
let mid = createVector( 0, 0);
let offset = createVector((gridSize * v), (gridSize * r));
for (let v = 0; v < cols; v++) {
for (let r = 0; r < rows; r++) {
let recta = new Recta(centers[v][r].x, centers[v][r].y);
let tile = new Tile(centers[v][r].x, centers[v][r].y);
tiles[v][r].hide(v, r, tiles);
setInterval( changeHides, 4000);
translate(sideMargin, verMargin);
for (let v = 0; v < cols; v++) {
for (let r = 0; r < rows; r++) {
for (let l = 0; l < letters.length; l++) {
letters[l].remove(letters);
if (keyCode === 32 || keyCode === 9) {
} else if (keyCode === 16 || keyCode === 13 || keyCode === 20 || keyCode === 8) {
} else if (keyCode === 17 || keyCode === 18 || keyCode === 91 || keyCode === 93 ) {
} else if (keyCode === 70 || keyCode === 85 || keyCode === 67 || keyCode === 75 ) {
} else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) {
} else if (keyCode === 49 || keyCode === 50 || keyCode === 51 || keyCode === 52 ) {
bgCol = color(187, 184, 169);
elemCol = color(20,20,20);
elemCol = color(187, 184, 169);
let letter = new Letter(key);
for (let v = 0; v < cols; v++) {
for (let r = 0; r < rows; r++) {
tiles[v][r].hide(v, r, tiles);
this.pos = createVector(gridSize * floor(random(cols)), gridSize * floor(random(rows)));
this.size = gridSize * ( floor(random(2, 6)) );
this.color = color(random(maxR, minR), random(maxG, minG), random(maxB, minB));
this.dir = random([0, 1]);
this.vel = createVector(0, 0)
this.speed = random(0.1, 0.5);
this.dotPos = -(this.size / 2) + (gridSize * 0.2);
rect(this.pos.x, this.pos.y, this.size, this.size);
textSize(this.size * 0.6);
text(this.key, this.pos.x, this.pos.y + (this.size * 0.35));
rect(this.pos.x + this.dotPos, this.pos.y + this.dotPos, gridSize * 0.2, gridSize * 0.2);
rect(this.pos.x - this.dotPos, this.pos.y + this.dotPos, gridSize * 0.2, gridSize * 0.2);
rect(this.pos.x + this.dotPos, this.pos.y - this.dotPos, gridSize * 0.2, gridSize * 0.2);
rect(this.pos.x - this.dotPos, this.pos.y - this.dotPos, gridSize * 0.2, gridSize * 0.2);
if(this.pos.y > height /2) {
let moveVer = createVector(0, this.speed);
} else if (this.dir == 1) {
if(this.pos.x > width /2) {
let moveHor = createVector(this.speed, 0);
if(this.pos.y > height || this.pos.y < -(this.size) ) {
for (let l = 0; l < arrayName.length; l++) {
if (arrayName[l].pos.y == this.pos.y) {
} else if (this.dir == 1) {
if(this.pos.x > width || this.pos.x < -(this.size) ) {
for (let l = 0; l < arrayName.length; l++) {
if (arrayName[l].pos.x == this.pos.x) {
this.pos = createVector( x + gridSize/2 , y + gridSize/2 );
this.firstSize = gridSize;
this.secSize = gridSize * 0.8;
this.thirSize = gridSize * 0.6;
this.fourSize = gridSize * 0.4;
this.fifSize = gridSize * 0.2;
this.center = createVector(0, 0);
this.shift = createVector(0, 0);
this.color = color(random(maxR, minR), random(maxG, minG), random(maxB, minB));
let tx = (v * gridSize) + gridSize / 2;
let ty = (r * gridSize) + gridSize / 2;
let rect0 = rect(this.pos.x, this.pos.y, this.firstSize, this.firstSize);
let rect1 = rect(this.center.x + this.shift.x, this.center.y + this.shift.y, this.secSize - this.offset1, this.secSize - this.offset1);
let rect2 = rect(this.pos.x + (this.shift.x *2), this.pos.y + (this.shift.y *2), this.thirSize, this.thirSize);
let rect3 = rect(this.center.x + (this.shift.x *3), this.center.y + (this.shift.y *3), this.fourSize, this.fourSize);
let rect4 = rect(this.pos.x + (this.shift.x *4) + this.offset2, this.pos.y + (this.shift.y *4) + this.offset2, this.fifSize, this.fifSize);
this.angle1 = this.angle1 + 1;
this.offset1 = this.offset1 + 0.5;
this.angle1 = this.angle1 - 1;
this.offset1 = this.offset1 - 0.5;
let moveR = createVector(this.speed, 0);
let moveL = createVector(-(this.speed), 0);
if (this.shift.x >= gridSize * 0.1) {
this.shift.x = gridSize * 0.1;
if (this.shift.x <= -(gridSize * 0.1)) {
this.shift.x = -(gridSize * 0.1);
let moveT = createVector(0, -(this.speed));
let moveB = createVector(0, this.speed);
if(this.shift.y >= gridSize * 0.1) {
this.shift.y = gridSize * 0.1;
if(this.shift.y <= -(gridSize * 0.1)) {
this.shift.y = -(gridSize * 0.1);
if(this.fifSize > this.thirSize) {
this.fifSize = this.thirSize;
this.fifSize = this.fifSize + this.zoomSp;
if(this.fifSize <= gridSize * 0.2) {
this.fifSize = gridSize * 0.2;
this.fifSize = this.fifSize - this.zoomSp;
if(this.firstSize < this.thirSize) {
this.firstSize = this.thirSize;
this.firstSize = this.firstSize - this.zoomSp;
if(this.firstSize >= gridSize) {
this.firstSize = gridSize;
this.firstSize = this.firstSize + this.zoomSp;
this.pos = createVector( x + gridSize/2 , y + gridSize/2 );
rect(this.pos.x, this.pos.y, this.size, this.size);
let hide = random([0, 1]);
this.color = color(0, 0, 0, 0);