← Mike Higgins Home
Custom Code Experiment •

Swarm

Source Code View HTML / CSS / JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Swarm Background (no text)</title>
  <style>
    body, html, #app {
      margin: 0;
      width: 100%;
      height: 100%;
    }

    #app {
      overflow: hidden;
      touch-action: pan-up;
    }

    #app canvas {
      display: block;
      position: fixed;
      z-index: -1;
      top: 0;
    }
  </style>
</head>
<body>
  <div id="app"></div>

  <script type="module">
    import { swarmBackground } from 'https://unpkg.com/threejs-toys@0.0.8/build/threejs-toys.module.cdn.min.js';

    const bg = swarmBackground({
      el: document.getElementById('app'),
      eventsEl: document.body,
      gpgpuSize: 256,
      color: [Math.random() * 0xffffff, Math.random() * 0xffffff],
      geometry: 'default'
    });

    bg.three.camera.position.set(0, 0, 200);

    document.body.addEventListener('click', () => {
      bg.setColors([Math.random() * 0xffffff, Math.random() * 0xffffff]);
    });
  </script>
</body>
</html>