<div class="display">
  <div class="panel panel--1">
    <code class="code code--step-0">
      <pre>--x and --y coordinates grid, with discrete values [-1, 0, 1]</pre>
    </code>
    <code class="code code--step-1">
      <pre>--cell-pattern-1: calc(var(--x) + var(--y) + 2);
--cell-pattern-2: calc(2 * var(--x) + #{abs(var(--y))} + 2);
--cell-pattern-3: calc(var(--x) - var(--y) + 2);
--cell-pattern-4: calc(#{abs(var(--x))} + 2 * var(--y) + 2);
--cell-pattern-5: calc(#{abs(var(--x))} + #{abs(var(--y))});
--cell-pattern-6: calc(#{abs(var(--x))} - 2 * var(--y) + 2);
--cell-pattern-7: calc(-1 * var(--x) + var(--y) + 2);
--cell-pattern-8: calc(-2 * var(--x) + #{abs(var(--y))} + 2);
--cell-pattern-9: calc(-1 * var(--x) - var(--y) + 2);</pre>
    </code>
    <code class="code code--step-2">
      <pre>boolean()</pre></code>
    <code class="code code--step-3">
      <pre>:not()</pre></code>
  </div>
  <div class="panel panel--2">
    <div class="result result--step-0"></div>
    <div class="result result--step-1"></div>
    <div class="result result--step-2"></div>
    <div class="result result--step-3"></div>
  </div>
</div>
body {
  margin: 0;
  font-family: monospace;
  font-size: calc(min(5vmin, 16px));
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background: #555;
  filter: sepia(0.25);
  color: #111;
}

.grid,
.subgrid {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  overflow: hidden;
}

.grid {
  background: #777;
  grid-gap: 5px;
}

.subgrid {
  --subgrid-gap: 2px;
  background: #999;
  grid-gap: var(--subgrid-gap);
  border-radius: 6px;
}

.subcell {
  background: #bbb;
  height: calc(min(6.5vmin, 24px));
  width: calc(min(6.5vmin, 24px));
  display: grid;
  place-items: center;
  border-radius: 3px;

  &.zero {
    background: #ddd;
  }

  &--span {
    grid-column: span 3;
    grid-row: span 3;
    height: calc(3 * min(6.5vmin, 24px) + 2 * var(--subgrid-gap));
    width: calc(3 * min(6.5vmin, 24px) + 2 * var(--subgrid-gap));
  }
}

.result {
  display: none;
}

.panel {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  gap: 1em;

  & > * {
    flex-shrink: 0;
    border: 5px solid #777;
    box-shadow: 0 1em 3em rgba(0, 0, 0, 0.25), 0 0.25em 1em rgba(0, 0, 0, 0.25);
    border-radius: 8px;
  }
}

.code {
  opacity: 0.5;
}

code,
pre {
  background: #ccc;
  color: inherit;
}

pre {
  margin: 0;
  font-size: 0.75em;
  padding: 1em;
  border-radius: 6px;
  word-break: break-all;
  max-width: 100vw;
  
  @media screen and (max-width: 500px) {
    white-space: wrap;
  }
}

.display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1em;

  &.step-0 .code--step-0,
  &.step-1 .code--step-0,
  &.step-1 .code--step-1,
  &.step-2 .code:not(.code--step-3),
  &.step-3 .code {
    opacity: 1;
  }

  &.step-0 .result--step-0,
  &.step-1 .result--step-1,
  &.step-2 .result--step-2,
  &.step-3 .result--step-3 {
    display: block;
  }
}
View Compiled
window.onload = () => {
  /*
	Formulas in CSS:
  
  --cell-pattern-1: calc(var(--x) + var(--y) + 2);
  --cell-pattern-2: calc(2 * var(--x) + #{abs(var(--y))} + 2);
  --cell-pattern-3: calc(var(--x) - var(--y) + 2);
  --cell-pattern-4: calc(#{abs(var(--x))} + 2 * var(--y) + 2);
  --cell-pattern-5: calc(#{abs(var(--x))} + #{abs(var(--y))});
  --cell-pattern-6: calc(#{abs(var(--x))} - 2 * var(--y) + 2);
  --cell-pattern-7: calc(-1 * var(--x) + var(--y) + 2);
  --cell-pattern-8: calc(-2 * var(--x) + #{abs(var(--y))} + 2);
  --cell-pattern-9: calc(-1 * var(--x) - var(--y) + 2);
  */

  const formulas = {
    1: (x, y) => x + y + 2,
    2: (x, y) => 2 * x + Math.abs(y) + 2,
    3: (x, y) => x - y + 2,
    4: (x, y) => Math.abs(x) + 2 * y + 2,
    5: (x, y) => Math.abs(x) + Math.abs(y),
    6: (x, y) => Math.abs(x) - 2 * y + 2,
    7: (x, y) => -x + y + 2,
    8: (x, y) => -2 * x + Math.abs(y) + 2,
    9: (x, y) => -x - y + 2
  }

  const coordinates = [
    [-1, -1],
    [-1, 0],
    [-1, 1],
    [0, -1],
    [0, 0],
    [0, 1],
    [1, -1],
    [1, 0],
    [1, 1],
  ]

  const results = coordinates.map(([x, y]) => {
    const resultsPerCell = [];
    Object.entries(formulas).map(([key, fn], index) => {
      resultsPerCell.push(fn(x, y));
    })

    return resultsPerCell;
  })

  const loopSteps = () => {
    const display = document.querySelector('.display');

    const cycleClasses = () => {
      var currentStep = 0;

      setInterval(function() {
        display.classList.remove('step-' + currentStep);

        currentStep = ((currentStep + 1) % 4);

        display.classList.add('step-' + currentStep);
      }, 1000);
    }

    cycleClasses();
  }

  loopSteps();

  const render = (nodeSelector, {
    boolean = false,
    not = false
  } = {}) => {
    const resultNode = document.querySelector(nodeSelector);

    const grid = document.createElement('div');
    grid.classList.add('grid');

    for (let subgridIdx = 0; subgridIdx < results.length; subgridIdx++) {
      const subgrid = document.createElement('div');
      subgrid.classList.add('subgrid');

      for (let subcellIdx = 0; subcellIdx < results[0].length; subcellIdx++) {
        const subcell = document.createElement('div');
        subcell.classList.add('subcell');
        const appliedFormula = results[subgridIdx][subcellIdx];
        subcell.textContent = appliedFormula;

        if (appliedFormula === 0) {
          subcell.classList.add('zero');
        }

        if (boolean) {
          subcell.textContent = Number(Boolean(appliedFormula));
        }

        if (not) {
          subcell.textContent = Number(!Boolean(appliedFormula));
        }

        subgrid.appendChild(subcell);
      }

      grid.appendChild(subgrid);
    }

    resultNode.appendChild(grid);
  }

  const renderCoordenates = (nodeSelector) => {
    const resultNode = document.querySelector(nodeSelector);

    const grid = document.createElement('div');
    grid.classList.add('grid');

    for (let subgridIdx = 0; subgridIdx < results.length; subgridIdx++) {
      const subgrid = document.createElement('div');
      subgrid.classList.add('subgrid');

        const subcell = document.createElement('div');
        subcell.classList.add('subcell');
        subcell.classList.add('subcell--span');
        subcell.textContent = `(${(subgridIdx % 3) - 1},${Math.floor(subgridIdx / 3) - 1})`;

        subgrid.appendChild(subcell);

      grid.appendChild(subgrid);
    }

    resultNode.appendChild(grid);
  }

  renderCoordenates('.result--step-0');
  render('.result--step-1');
  render('.result--step-2', {
    boolean: true
  });
  render('.result--step-3', {
    boolean: true,
    not: true
  });
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.