Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <!--  

A basic experiment with moving 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 = 40000;
const begin = 0.4;
const duration = 0.6;

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;
}

const attributes = [
  {
    name: "aPositionStart",
    data: (index, total) => {
      return [
        0, 
        -1, 
        0,
      ];
    },
    size: 3
  },
  {
    name: "aControlPointOne",
    data: (index, total) => {
      const angle = index * (2 * Math.PI / total);
      return [
        Math.cos(angle) * 1.5 + getRandom(0.5),
        1.5 + getRandom(0.5),
        Math.sin(angle) * 1.5,
      ];
    },
    size: 3
  },
  {
    name: "aControlPointTwo",
    data: (index, total) => {
      const angle = index * (2 * Math.PI / total);
      return [
        Math.cos(angle) + getRandom(1),
        1 + getRandom(0.5),
        Math.sin(angle) + getRandom(1)
      ];
    },
    size: 3
  },
  {
    name: "aPositionEnd",
    data: (index, total) => {
      const angle = index * (2 * Math.PI / total);
      return [
        Math.cos(angle) + getRandom(2), 
        -2, 
        0,
      ];
    },
    size: 3
  },
  {
    name: "aColor",
    data: (index, total) =>
      getHSL(
        begin + index / total * 0.2,
        0.6 + getRandom(0.1),
        0.6 + getRandom(0.1),
      ),
    size: 3
  },
  {
    name: "aOffset",
    data: i => [i * ((1 - duration) / (multiplier - 1))],
    size: 1
  }
];

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

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

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

  varying vec3 vColor;

  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);
  }

  void main(){
    float tProgress = min(1.0, max(0.0, (uProgress - aOffset)) / ${duration});
    vec3 newPosition = bezier4(aPositionStart, aControlPointOne, aControlPointTwo, aPositionEnd, tProgress);
    gl_PointSize = 4.0;
    gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * vec4(newPosition + aPosition, 1.0);
    vColor = aColor;
  }
`;

const fragment = `
  precision mediump float;

  varying vec3 vColor;

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

const renderer = new Phenomenon({
  canvas: document.querySelector("canvas"),
  settings: {
    clearColor: [239 / 255, 239 / 255, 239 / 255, 1],
    position: {x: 0, y: 0, z: 1.2 },
    shouldRender: true
  }
});

renderer.add("starling", {
  attributes,
  multiplier,
  uniforms,
  vertex,
  fragment,
  onRender: instance => {
    instance.uniforms.uProgress.value += 0.004;
    if (instance.uniforms.uProgress.value >= 1.2) {
      instance.uniforms.uProgress.value = 0;
    }
  }
});

              
            
!
999px

Console