kitbash Sign in Connect agent
Components

Ray lab

Black canvas of rotating red god rays with an experiment list; hovering an item changes the rays and the counter.

Part of the style

Teal Haze Lab

6 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --field: #b2967d;
  --ink: #060001;
  --night: #1d0a0e;
  --night-ink: #eed0b6;
  --screen: #2a1419;
  --screen-ink: #eed0b6;
  --paper: #eed0b6;
  --ray: #ac846a;
  --glow: #90715d;
  --field-deep: #734742;
  --field-bright: #b36860;
  --lilac: #b36f5d;
  --pink: #a16e56;
}
</style>

<section class="lab">
  <canvas class="lab__rays" role="img" aria-label="Red light rays turning slowly around a point"></canvas>
  <p class="lab__label">The Lab</p>
  <p class="lab__note">Open sketches,<br>mostly broken</p>
  <div class="lab__index">
    <p class="lab__count"><span class="lab__diamond" aria-hidden="true"></span><span><span class="lab__count-now">00</span> of 12</span></p>
    <span class="lab__marker" aria-hidden="true"></span>
    <ul class="lab__list">
      <li><a class="lab__item" href="#" data-rays="5">Wave table</a></li>
      <li><a class="lab__item" href="#" data-rays="9">Feedback loop</a></li>
      <li><a class="lab__item" href="#" data-rays="14">Granular fog</a></li>
      <li><a class="lab__item" href="#" data-rays="3">Tape smear</a></li>
      <li><a class="lab__item" href="#" data-rays="20">Room tone</a></li>
      <li><a class="lab__item" href="#" data-rays="7">Long shadow</a></li>
    </ul>
  </div>
</section>

<style>
  .lab {
    position: relative;
    isolation: isolate;
    height: clamp(560px, 52vw, 780px);
    padding: var(--space-m) var(--edge);
    overflow: hidden;
    background: var(--night);
    color: var(--night-ink);
  }
  .lab__rays {
    position: absolute;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    max-width: none;
    color: var(--ray);
  }
  .lab__label,
  .lab__note {
    position: absolute;
    top: var(--space-m);
    margin: 0;
  }
  .lab__label {
    left: var(--edge);
  }
  .lab__note {
    right: var(--edge);
    text-align: right;
  }
  .lab__index {
    position: absolute;
    left: clamp(var(--edge), 6vw, 120px);
    top: 50%;
    translate: 0 -50%;
    display: grid;
    grid-template-columns: auto auto;
    column-gap: var(--space-m);
    align-items: start;
  }
  .lab__count {
    grid-column: 2;
    display: flex;
    align-items: center;
    gap: var(--space-m);
    margin: 0 0 var(--space-s);
  }
  .lab__diamond {
    width: 6px;
    height: 6px;
    background: currentColor;
    rotate: 45deg;
  }
  .lab__marker {
    grid-column: 1;
    grid-row: 2;
    width: 34px;
    height: 34px;
    margin-top: 5px;
    background: var(--pink);
    translate: 0 calc(var(--lab-active, 0) * var(--tap));
    transition: translate 500ms var(--ease-out);
  }
  .lab__list {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .lab__item {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity var(--quick) var(--ease), letter-spacing var(--quick) var(--ease);
  }
  .lab__item:hover,
  .lab__item:focus-visible,
  .lab__item.is-current {
    opacity: 1;
    letter-spacing: 0.08em;
    outline: none;
  }

  @media (max-width: 40rem) {
    .lab__index {
      top: auto;
      bottom: var(--space-l);
      translate: none;
    }
  }
</style>

<script>
  (() => {
    const still = matchMedia('(prefers-reduced-motion: reduce)');

    const rgba = (hex, alpha) => {
      const value = parseInt(hex.replace('#', ''), 16);
      return `rgba(${value >> 16}, ${(value >> 8) & 255}, ${value & 255}, ${alpha})`;
    };

    function paint(context, width, height, seconds, rays, color, narrow) {
      const centerX = width * (narrow ? 0.5 : 0.58);
      const centerY = height * (narrow ? 0.36 : 0.5);
      const reach = Math.max(width, height) * 0.62;
      context.globalCompositeOperation = 'source-over';
      context.clearRect(0, 0, width, height);
      context.globalCompositeOperation = 'lighter';

      const light = context.createRadialGradient(centerX, centerY, 0, centerX, centerY, reach);
      light.addColorStop(0, rgba(color, 0.8));
      light.addColorStop(0.3, rgba(color, 0.22));
      light.addColorStop(1, rgba(color, 0));
      context.fillStyle = light;

      const count = Math.max(1, Math.round(rays.count));
      const spread = 0.03 + 0.18 / count;
      context.globalAlpha = 0.34;
      for (let index = 0; index < count; index += 1) {
        const angle = seconds * 0.12 + (index / count) * Math.PI * 2 + Math.sin(seconds * 0.6 + index) * 0.05;
        const length = reach * (0.7 + 0.3 * Math.sin(seconds * 0.9 + index * 1.7));
        for (const soften of [0.4, 1, 1.9]) {
          context.beginPath();
          context.moveTo(centerX, centerY);
          context.lineTo(centerX + Math.cos(angle - spread * soften) * length, centerY + Math.sin(angle - spread * soften) * length);
          context.lineTo(centerX + Math.cos(angle + spread * soften) * length, centerY + Math.sin(angle + spread * soften) * length);
          context.closePath();
          context.fill();
        }
      }
      context.globalAlpha = 1;

      const core = context.createRadialGradient(centerX, centerY, 0, centerX, centerY, reach * 0.12);
      core.addColorStop(0, rgba(color, 0.7));
      core.addColorStop(1, rgba(color, 0));
      context.fillStyle = core;
      context.fillRect(0, 0, width, height);
    }

    function run(lab) {
      const canvas = lab.querySelector('.lab__rays');
      const context = canvas.getContext('2d');
      const buffer = document.createElement('canvas');
      const bufferContext = buffer.getContext('2d');
      const color = getComputedStyle(lab).getPropertyValue('--ray').trim();
      const counter = lab.querySelector('.lab__count-now');
      const items = [...lab.querySelectorAll('.lab__item')];
      const rays = { count: 8, target: 8 };
      let frame = 0;

      const draw = (seconds) => {
        rays.count += (rays.target - rays.count) * 0.06;
        paint(bufferContext, buffer.width, buffer.height, seconds, rays, color, canvas.clientWidth < 640);
        context.clearRect(0, 0, canvas.width, canvas.height);
        context.drawImage(buffer, 0, 0, canvas.width, canvas.height);
      };
      const fit = () => {
        const density = Math.min(2, devicePixelRatio || 1);
        canvas.width = canvas.clientWidth * density;
        canvas.height = canvas.clientHeight * density;
        buffer.width = Math.max(1, Math.round(canvas.clientWidth / 7));
        buffer.height = Math.max(1, Math.round(canvas.clientHeight / 7));
        draw(performance.now() / 1000);
      };
      const tick = (now) => {
        draw(now / 1000);
        frame = requestAnimationFrame(tick);
      };

      const choose = (index) => {
        items.forEach((item, order) => item.classList.toggle('is-current', order === index));
        lab.style.setProperty('--lab-active', Math.max(0, index));
        counter.textContent = String(index + 1).padStart(2, '0');
        rays.target = index < 0 ? 8 : Number(items[index].dataset.rays);
        if (still.matches) {
          rays.count = rays.target;
          draw(0);
        }
      };
      items.forEach((item, index) => {
        item.addEventListener('pointerenter', () => choose(index));
        item.addEventListener('focus', () => choose(index));
      });
      lab.querySelector('.lab__list').addEventListener('pointerleave', () => choose(-1));

      new ResizeObserver(fit).observe(canvas);
      new IntersectionObserver(([entry]) => {
        cancelAnimationFrame(frame);
        if (entry.isIntersecting && !still.matches) frame = requestAnimationFrame(tick);
      }).observe(canvas);
    }

    document.querySelectorAll('.lab').forEach(run);
  })();
</script>

Similar components

Services list

Services list

Ledger

Ledger

Ruled lists

Ruled lists

Ringed services

Ringed services

Coming soon

Coming soon

Scan-weight index

Scan-weight index

Capability rows

Capability rows

News

News