<div class="wrapper">
  <canvas id="canvas"></canvas>
</div>
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

.wrapper {
  width: 100%;
  height: 100%;
}

canvas {
  image-rendering: pixelated;
}
const outputContainer = document.getElementsByClassName("wrapper")[0];
const ctx = canvas.getContext("2d");

canvas.width = outputContainer.offsetWidth;
canvas.height = outputContainer.offsetHeight;

const colors = ["#73066f", "#ea21a1", "#fe7985", "#efe36c"];
let pixelSize = 2;
const animationInterval = 200;

animate();

function animate(time) {
  if (pixelSize >= 140) {
    pixelSize = 2; // Reset back to start
    requestAnimationFrame(animate);
  } else {
    for (let y = 0; y < canvas.height; y += pixelSize) {
      for (let x = 0; x < canvas.width; x += pixelSize) {
        ctx.fillStyle = colors[randomNum(0, colors.length - 1)];
        ctx.fillRect(x, y, pixelSize, pixelSize);
      }
    }

    pixelSize += 2;

    setTimeout(() => {
      requestAnimationFrame(animate);
    }, animationInterval);
  }
}

function randomNum(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.