<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS Art</title>
</head>

<body>
  <div class="grid-container"></div>
</body>

</html>
html,
body {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background-color: black;
}

.grid-container {
  height: 500px;
  width: 500px;

  align-items: center;
  justify-content: center;

  display: grid;
  grid-template-columns: repeat(8, calc(500px / 8));
  grid-template-rows: repeat(8, calc(500px / 8));
  gap: 0px;

  background-color: #258f25;
  border: 5px solid darkgreen;
}

.grid-item {
  height: 100%;
  width: 100%;

  display: flex;
  justify-content: center;
  align-items: center;

  background-color: white;
}

.grid-item:hover {
  filter: brightness(50%);
  animation-name: hover-animation;
  animation-duration: 0.5s;
}

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

@keyframes hover-animation {
  from {
    filter: brightness(100%);
  }
  to {
    filter: brightness(50%);
  }
}

@keyframes background-animation {
  from {
    filter: brightness(50%);
  }
  to {
    filter: brightness(100%);
  }
}

@keyframes circle-animation {
  from {
    filter: brightness(30%);
  }
  to {
    filter: brightness(80%);
  }
}
container = document.getElementsByClassName("grid-container")[0];
items = document.getElementsByClassName("grid-item");
color = ["#ede855", "#ed5f55", "#55c2ed", "#edbd55", "#ed55d4", "#55e8ed"];
grass = ["green", "#258f25", "green"];

function explode(e) {
  if (!e.target.querySelector("div")) {
    if (e.target.classList[0] != "circle") {
      const num = Math.floor(Math.random() * 65);
      e.target.style.backgroundColor = color[num % 6];

      circle = document.createElement("div");
      circle.classList.add("circle");

      circle.style.backgroundColor = color[num % 6];
      circle.style.filter = "brightness(80%)";
      circle.style.animationName = "circle-animation";
      circle.style.animationDuration = "0.5s";
      circle.style.borderRadius = "50px";
      circle.style.width = "30px";
      circle.style.height = "30px";

      e.target.style.backgroundColor = color[num % 6];
      e.target.style.animationName = "background-animation";
      e.target.style.animationDuration = "0.5s";
      e.target.style.filter = "brightness(100%)";

      e.target.appendChild(circle);
    }
  }
}

var toggle = false;
for (var i = 0; i < 64; i++) {
  item = document.createElement("div");
  item.classList.add("grid-item");

  if (i % 8 == 0) {
    toggle = !toggle;
  }

  if (toggle) {
    item.style.backgroundColor = grass[(i % 2) + 1];
  } else {
    item.style.backgroundColor = grass[i % 2];
  }

  item.addEventListener("click", (e) => explode(e));

  container.appendChild(item);
}

nums = [];
for (var j = 0; j < 10; j++) {
  num = Math.floor(Math.random() * 65);
  while (nums.includes(num)) {
    num = Math.floor(Math.random() * 65);
  }
  nums.push(num);
  circle = document.createElement("div");
  circle.classList.add("circle");

  circle.style.backgroundColor = color[num % 6];
  circle.style.filter = "brightness(80%)";
  circle.style.animationName = "circle-animation";
  circle.style.animationDuration = "0.5s";
  circle.style.borderRadius = "50px";
  circle.style.width = "30px";
  circle.style.height = "30px";

  items[num].style.backgroundColor = color[num % 6];
  items[num].style.animationName = "background-animation";
  items[num].style.animationDuration = 0.5 + j / 2 + "s";
  items[num].style.filter = "brightness(100%)";

  items[num].appendChild(circle);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.