Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <!--  

An experiment with multiple instances (5 x 10000 particles)!

Made with Phenomenon: A fast 2kB low-level WebGL API! ✨

https://github.com/vaneenige/phenomenon

-->

<canvas />
            
          
!

CSS

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

canvas {
  position: fixed;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

            
          
!

JS

            
              const multiplier = 10000;
const begin = 0.4;
const duration = 0.8;

let forward = true;

const renderer = new Phenomenon({
  canvas: document.querySelector("canvas"),
  settings: {
    clearColor: [239 / 255, 239 / 255, 239 / 255, 1],
    position: {x: 0, y: 0, z: 1.4 },
    uniforms: {
      uProgress: {
        type: "float",
        value: 0.0
      }
    },
    shouldRender: true,
    onRender: ({ uniforms }) => {
      uniforms.uProgress.value += forward ? 0.008: -0.008;
      if (uniforms.uProgress.value >= 1) {
        forward = false;
      }
      if (uniforms.uProgress.value <= 0) {
        forward = true;
      }
    }
  }
});

function h2r(p, q, t) {
  if (t < 0) t += 1;
  if (t > 1) t -= 1;
  if (t < 1 / 6) return p + (q - p) * 6 * t;
  if (t < 1 / 2) return q;
  if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  return p;
}

function getHSL(h, s, l) {
  h = (h % 1 + 1) % 1;
  s = Math.max(0, Math.min(1, s));
  l = Math.max(0, Math.min(1, l));
  if (s === 0) return [l, l, l];
  const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  const q = 2 * l - p;
  return [h2r(q, p, h + 1 / 3), h2r(q, p, h), h2r(q, p, h - 1 / 3)];
}

function getRandom(value) {
  const floor = -value;
  return floor + Math.random() * value * 2;
}

function instance(value) {
 

  const attributes = [
{
      name: 'aPositionOffset',
      size: 3,
      data: () => [getRandom(0.1), getRandom(0.1), getRandom(0.1)],
    },
    {
      name: 'aColor',
      size: 3,
      data: (index, total) => 
        getHSL(
        begin + index / total * 0.2,
        0.6 + getRandom(0.1),
        0.6 + getRandom(0.1)
      ),
    },
    {
      name: 'aAngle',
      size: 1,
      data: i => [(i % 2 === 0) ? -1.0 : 1.0],
    },
    {
      name: 'aOffset',
      size: 1,
      data: i => [i * ((1 - duration) / (multiplier - 1))],
    },
  ];

  const vertex = `
    attribute vec3 aPosition;
    attribute vec3 aPositionOffset;
    attribute vec3 aColor;  
    attribute float aOffset;  
    attribute float aAngle;  

    uniform float uProgress;
    uniform mat4 uProjectionMatrix;
    uniform mat4 uModelMatrix;
    uniform mat4 uViewMatrix;

    varying vec3 vColor;
    varying float vProgress;

    void main(){
        float tProgress = min(1.0, max(0.0, (uProgress - aOffset)) / ${duration});
        vec3 newPosition = vec3(${-1 + (value / 5) * 2 + 0.2}, -1.2, 0.0) + 
        vec3(
          sin((10.0 * aAngle) * tProgress) * (0.6 * tProgress),  
          3.4 * tProgress,
cos((10.0 * aAngle) * tProgress) * (aAngle * (0.6 * tProgress))
        );
      gl_PointSize = 3.0;
      gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * vec4(newPosition + aPosition + (tProgress * aPositionOffset), 1.0);
      vColor = aColor;
      vProgress = tProgress;
    }
  `;

  const fragment = `
    precision mediump float;

    varying vec3 vColor;
    varying float vProgress;

    void main(){
      gl_FragColor = vec4(vColor, 1.0);
    }
  `;

  renderer.add(Math.random(), {
    attributes,
    multiplier,
    vertex,
    fragment
  });
}

instance(0);
instance(1);
instance(2);
instance(3);
instance(4);

            
          
!
999px

Console