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

            
              <!-- 

Here's Phenomenon: A fast 2kB low-level WebGL API! ✨

✅ GPU based for high performance
✅ Highly configurable with shaders
✅ Add & destroy instances on the fly
✅ Convenient hooks and parameters
✅ Particles, particles, particles!

https://github.com/vaneenige/phenomenon

-->

<canvas></canvas>
<a href="https://github.com/vaneenige/phenomenon" target="_blank">Phenomenon</a>
            
          
!

CSS

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

  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
  letter-spacing: 0;
  font-style: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a {
  position: fixed;
  margin: 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  border-radius: 0;
  cursor: pointer;
  outline: none;
  padding: 8px 20px;
  border: 2px solid rgb(29, 233, 182);
  color: rgb(29, 233, 182);
}

a:hover,
a:focus {
  color: white;
  background-color: rgb(29, 233, 182);
}
            
          
!

JS

            
              function rotateX(m, angle) {
  let c = Math.cos(angle);
  let s = Math.sin(angle);
  let mv1 = m[1];
  let mv5 = m[5];
  let mv9 = m[9];

  m[1] = m[1] * c - m[2] * s;
  m[5] = m[5] * c - m[6] * s;
  m[9] = m[9] * c - m[10] * s;

  m[2] = m[2] * c + mv1 * s;
  m[6] = m[6] * c + mv5 * s;
  m[10] = m[10] * c + mv9 * s;
}

function rotateY(m, angle) {
  let c = Math.cos(angle);
  let s = Math.sin(angle);
  let mv0 = m[0];
  let mv4 = m[4];
  let mv8 = m[8];

  m[0] = c * m[0] + s * m[2];
  m[4] = c * m[4] + s * m[6];
  m[8] = c * m[8] + s * m[10];

  m[2] = c * m[2] - s * mv0;
  m[6] = c * m[6] - s * mv4;
  m[10] = c * m[10] - s * mv8;
}

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


// The amount of particles that will be created
const multiplier = 400000;

// Percentage of how long every particle will move
const duration = 0.9;

// Update value for every frame
const step = 0.01;

// Multiplier of the canvas resolution
const devicePixelRatio = 1;

// Every attribute must have:
// - Name (used in the shader)
// - Data (returns data for every particle)
// - Size (amount of variables in the data)
const attributes = [
  {
    name: 'aPositionStart',
    data: () => [getRandom(0.5), getRandom(0.5), getRandom(0.5)],
    size: 3,
  },
  {
    name: 'aPositionEnd',
    data: () => [getRandom(1.5), getRandom(1.5), getRandom(1.5)],
    size: 3,
  },
  {
    name: 'aColor',
    data: () => Math.random() > 0.5 ? [29 / 255, 233 / 255, 182 / 255, 1] : [4 / 255, 208 / 255, 157 / 255, 1],
    size: 3,
  },
  {
    name: 'aOffset',
    data: i => [i * ((1 - duration) / (multiplier - 1))],
    size: 1,
  },
];

// Every uniform must have:
// - Key (used in the shader)
// - Type (what kind of value)
// - Value (based on the type)
const uniforms = {
  uProgress: {
    type: 'float',
    value: 0.0,
  },
};

// Vertex shader used to calculate the position
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;

  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 = mix(aPositionStart, aPositionEnd, tProgress);
    gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * vec4(newPosition + aPosition, 1.0);
    gl_PointSize = ${devicePixelRatio.toFixed(1)};
    vColor = aColor;
  }
`;

// Fragment shader to draw the colored pixels to the canvas
const fragment = `
  precision mediump float;

  varying vec3 vColor;

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

// Boolean value to switch direction
let forward = true;

// Create the renderer
const phenomenon = new Phenomenon({
  settings: {
    devicePixelRatio,
    position: { x: 0, y: 0, z: 3 },
    shouldRender: true,
    uniforms,
    onRender: r => {
      const { uProgress, uModelMatrix } = r.uniforms;
      uProgress.value += forward ? step : -step;

      if (uProgress.value >= 1) forward = false;
      else if (uProgress.value <= 0) forward = true;

      rotateY(uModelMatrix.value, step * 2);
      rotateX(uModelMatrix.value, step * 2);
    },
  },
});

// Add an instance to the renderer
phenomenon.add('cube', {
  attributes,
  multiplier,
  vertex,
  fragment,
});

            
          
!
999px

Console