css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container" style="display: none;">
  <canvas></canvas>
  <h1>Happy Holidays</h1>
</div>
            
          
!
            
              @import url("https://fonts.googleapis.com/css?family=Dancing+Script");

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Dancing Script", cursive;
  letter-spacing: 0;
  font-style: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: white;
  font-size: 72px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fbe9e7 0%, #fff3e0 100%);
}

h1 {
  padding: 24px;
  margin: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%) translateZ(80px);
}

canvas {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
}
.container {
  transform-style: preserve-3d;
  position: relative;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

* {
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

            
          
!
            
              const canvas = document.querySelector("canvas");
const container = document.querySelector(".container");

if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent) === false) {
  VanillaTilt.init(container, { speed: 2000 });
}

const imageSize = 60;
let lowest;

const resize = () => {
  const maxWidth = Math.floor((window.innerWidth - 56) / imageSize);
  const maxHeight = Math.floor((window.innerHeight - 56) / imageSize);

  lowest = maxWidth < maxHeight ? maxWidth : maxHeight;
  if (lowest > 10) lowest = 10;

  container.style.width = `${lowest * imageSize}px`;
  container.style.height = `${lowest * imageSize}px`;
  container.style.display = 'block';
  document.body.style.fontSize = `${lowest * imageSize / 10}px`;
};

const initialize = image => {
  const imageSize = 60;
  const pixelRatio = window.devicePixelRatio;
  resize();
  window.addEventListener("resize", resize);
  const columns = lowest * pixelRatio;
  const rows = lowest * pixelRatio;
  const multiplier = rows * rows;
  const duration = 0.6;
  const geometry = [{ x: 0, y: 0, z: 0 }];
  const pointSize = imageSize.toFixed(1);
  const step = 0.004;
  let forward = true;
  const offset = 0.5;
  const attributes = [
    {
      name: "aPositionStart",
      data: i => [0, -1.2, 0]
    },
    {
      name: "aControlPointOne",
      data: (i, total) => [0, 0, 0]
    },
    {
      name: "aControlPointTwo",
      data: (i, total) => [getRandom(1), getRandom(1), getRandom(1)]
    },
    {
      name: "aPositionEnd",
      data: i => [
        1 - ((i % rows) / rows + 0.5 / rows) * 2,
        1 - (Math.floor(i / rows) / rows + 0.5 / rows) * 2,
        0
      ]
    },
    {
      name: "aOffset",
      data: i => [i * ((1 - duration) / (multiplier - 1))]
    }
  ];

  const uniforms = [
    {
      name: "uProgress",
      type: "float",
      value: 0.0
    }
  ];

  const vertexShader = `
    attribute vec3 aPositionStart;
    attribute vec3 aControlPointOne;
    attribute vec3 aControlPointTwo;
    attribute vec3 aPositionEnd;
    attribute float aOffset;
    attribute vec3 aColor;

    uniform float uProgress;
    uniform mat4 uMVP;

    vec3 bezier4(vec3 a, vec3 b, vec3 c, vec3 d, float t) {
      return mix(mix(mix(a, b, t), mix(b, c, t), t), mix(mix(b, c, t), mix(c, d, t), t), t);
    }

    float easeInOutQuint(float t){
      return t < 0.5 ? 16.0 * t * t * t * t * t : 1.0 + 16.0 * (--t) * t * t * t * t;
    }

    void main () {
      float tProgress = easeInOutQuint(min(1.0, max(0.0, (uProgress - aOffset)) / ${duration}));
      vec3 newPosition = bezier4(aPositionStart, aControlPointOne, aControlPointTwo, aPositionEnd, tProgress);
      gl_PointSize = ${pointSize};
      gl_Position = uMVP * vec4(newPosition, 1.0);
    }
  `;

  const fragmentShader = `
    precision mediump float;

    uniform sampler2D uSampler;

    void main() {
      gl_FragColor = texture2D(uSampler, gl_PointCoord);
    }
  `;

  const onSetup = gl => {
    texture = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, image);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    gl.bindTexture(gl.TEXTURE_2D, null);
  };

  const onRepeat = (gl, program) => {
    const uSampler = gl.getUniformLocation(program, "uSampler");
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.uniform1i(uSampler, 0);

    if (uniforms[0].value > 1) {
      forward = false;
    } else if (uniforms[0].value < 0) {
      forward = true;
    }
    uniforms[0].value += forward ? step : -step;
  };

  const options = {
    onSetup,
    onRepeat,
    pixelRatio
  };

  starlings(
    canvas,
    geometry,
    multiplier,
    attributes,
    uniforms,
    vertexShader,
    fragmentShader,
    options
  );
};

const getRandom = value => Math.random() * value - value / 2;

const loadImage = callback => {
  const image = new Image();
  image.onload = () => {
    callback(image);
  };
  image.crossOrigin = "Anonymous";
  image.src = `https://use-the-platform.com/${Math.random() > 0.1 ? 1 : 2}.png`;
};

loadImage(initialize);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console