cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="scene">
- for i in (1..(9*9))
  .cell
</div>

<a class="reference" href="https://twitter.com/beesandbombs/status/930237266525552640" target="_blank">inspiration</a>
            
          
!
            
              $ease: cubic-bezier(0.77, 0, 0.175, 1);
$anim: anim-todo 3s $ease infinite;
$len: 6vmin;

*,
:before,
:after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
}

body {
  font-display: swap;
  font-family: "Handlee", sans-serif;
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: radial-gradient(#777, black);
  position: relative;
  &:before{
    display: block;
    content: '';
    opacity: 0;
    transition: 400ms;
    background: white;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }
  &.toggled {
    .cell > span {
      font-family: sans-serif;
      background: transparent !important; // override inline style
    }
    &:before{
      opacity: 1;
    }
  }
}

.scene {
  $size: 9*9vmin;
  width: $size;
  height: $size;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  grid-gap: 0px;
  &.animate {
    .cell:nth-child(odd) {
      animation-name: anim;
    }
  }
}
.cell {
  transform: translateY($len);
  display: flex;
  //  flex-direction: column;
  justify-content: stretch;
  align-items: stretch;
  font-size: 4vmin;
  padding: 1px;
  font-weight: 300;
  transform-origin: 50% 50%;
  color: #333;
  //outline: 1px solid red;

  > span {
    border-radius: 50%;
    width: 100%;
    display: block;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: font-family 300ms, background-color 300ms;
    > span {
      display: block;
      padding: 0 1px;
    }
  }

  &:nth-child(odd) {
    animation: $anim;
  }
  &.center {
  }
}

@keyframes anim {
  0% {
    transform: translateY($len);
  }
  25% {
    transform: translateY(-$len);
  }
  50% {
    transform: translateY(-$len) rotate(0.4999turn);
    // force correct rotate direction by this wierd number
  }
  75% {
    transform: translateY($len) rotate(0.5001turn);
  }
  100% {
    transform: translateY($len) rotate(1turn);
  }
}

.reference{
  position: absolute;
  bottom: 2px;
  right: 2px;
  color: #5a5a5a;
  font-size: 12px;
  padding: 2px;
  transition: 280ms;
  border-radius: 2px;
  &:hover{
    background: rgba(white,.1);
  }
}
            
          
!
            
              polyfill();
const log = console.log.bind(console);
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
const rAF = window.requestAnimationFrame.bind(window);

setup();






function setup() {
  let scene = qs(".scene");
  scene.addEventListener("click", () =>
    document.body.classList.toggle("toggled")
  );

  let cells = qsa(".cell:nth-child(odd)", scene);
  let center = cells[~~(cells.length / 2)];
  center.classList.add("center");
  let cRect = center.getBoundingClientRect();

  let dists = [];
  cells.forEach(c => {
    c.innerHTML = "<span> <span>u</span> <span>p</span> </span>";
    let rect = c.getBoundingClientRect();
    let dist = distance(cRect.x, cRect.y, rect.x, rect.y);
    dist = Math.round(dist * 100) / 100;
    dists.push({ el: c, dist });
  });

  const max = Math.max(...dists.map(d => d.dist));

  dists.forEach(d => {
    let delay = Math.round(rangeMap(d.dist, 0, max, 0, 200));
    let light = Math.round(rangeMap(d.dist, 0, max, 0, 80));
    let hue = Math.round(rangeMap(d.dist, 0, max, 0, 220));
    d.el.style.animationDelay = `${delay}ms`;
    //d.el.style.color = `hsl(${0}, 0%, ${light}%)`;

    // Using span because using vmin values can give pixel rounding errors. Applying 1px padding to ensure graphical correct circles.
    d.el.querySelector("span").style.backgroundColor = `hsl(${hue}, 50%, 80%)`;
  });

  // Animate when delay values has been set. Only start when we are ready.
  setTimeout(() => scene.classList.add("animate"), 100);
}

function qs(expr, context) {
  return (context || document).querySelector(expr);
}
function qsa(expr, context) {
  return [].slice.call((context || document).querySelectorAll(expr), 0);
}

function rangeMap(x, a, b, c, d) {
  if (a === b) return c;
  if (c === d) return c;
  return (x - a) / (b - a) * (d - c) + c;
}



function polyfill() {
  Math.hypot =
    Math.hypot ||
    function(x, y) {
      // https://bugzilla.mozilla.org/show_bug.cgi?id=896264#c28
      var max = 0;
      var s = 0;
      for (var i = 0; i < arguments.length; i += 1) {
        var arg = Math.abs(Number(arguments[i]));
        if (arg > max) {
          s *= max / arg * (max / arg);
          max = arg;
        }
        s += arg === 0 && max === 0 ? 0 : arg / max * (arg / max);
      }
      return max === 1 / 0 ? 1 / 0 : max * Math.sqrt(s);
    };
}

            
          
!
999px
Loading ..................

Console