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.

            
              <canvas id="canvas"></div>
<script id="vertex-shader" type="x-shader/x-vertex">
  attribute vec2 a_position;

  void main(void) {
    gl_Position = vec4(a_position, 0, 1);
  }
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
  #ifdef GL_ES
  precision mediump float;
  #endif

  uniform vec2 u_resolution;
  uniform float u_millis;

  const int PARTICLES = 18;
  const float ENERGY = 0.2;
  const float BLOBINESS = 1.6;
  const float BRIGHTNESS = 1.1;
  const float OFFSET = 30000.0;

  float rand(vec2 co) {
    return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
  }

  void main(void) {
    vec2 pixel = (gl_FragCoord.xy / u_resolution.x);
    float t = (u_millis + OFFSET ) * 0.001 * ENERGY;

    float a = 0.0;
    float b = 0.0;
    float c = 0.0;

    vec2 particle;
    vec2 center = vec2(0.5, 0.5 * (u_resolution.y / u_resolution.x));

    float na, nb, nc, nd, d;
    float size = float(PARTICLES);
    float step = 1.0 / size;
    float n = step;

    for (int i = 0; i < PARTICLES; i++) {
      vec2 np = vec2(n, 0.0);

      na = rand(np * 1.1);
      nb = rand(np * 2.8);
      nc = rand(np * 0.7);
      nd = rand(np * 3.2);

      particle = center;
      particle.x += sin(t*na) * cos(t*nb) * 0.6;
      particle.y += cos(t*nc) * sin(t*nd) * 0.4;

      d = pow(1.2 * na / length(particle - pixel), BLOBINESS);

      if (float(i) < size * 0.3333) {
        a += d;
      } else if (float(i) < size * 0.6666) {
        b += d;
      } else {
        c += d;
      }

      n += step;
    }

    vec3 col = vec3(a*c, b*c, a*b) * 0.0001 * BRIGHTNESS;
    gl_FragColor = vec4(col, 1.0);
  }
</script>

            
          
!
            
              html, body {
  background: #111;
  overflow: hidden;
  margin: 0;
}

canvas {
  width: 100vw;
  height: 100vh;
}
            
          
!
            
              'use strict';

// Create program
const canvas = document.getElementById("canvas");
const gl = canvas.getContext('webgl');
const program = webglUtils.createProgramFromScripts(gl, ['vertex-shader', 'fragment-shader']);

// Create and initialize buffer
const geometryBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, geometryBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  -1.0, -1.0,
   1.0, -1.0,
  -1.0,  1.0,
   1.0,  1.0
]), gl.STATIC_DRAW);

// Set up attributes and uniforms
const attributes = {
  position: gl.getAttribLocation(program, 'a_position')
};

const uniforms = {
  resolution: gl.getUniformLocation(program, 'u_resolution'),
  millis: gl.getUniformLocation(program, 'u_millis')
};

// Set WebGL program here (we have only one)
gl.useProgram(program);

// Setup canvas
window.onresize = resize;
resize();

// Start rendering
requestAnimationFrame(draw);

// Resize canvas and viewport
function resize () {
  webglUtils.resizeCanvasToDisplaySize(gl.canvas);
  gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
}

// Draw frame
function draw (now) {
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  gl.bindBuffer(gl.ARRAY_BUFFER, geometryBuffer);

  gl.enableVertexAttribArray(attributes.position);
  gl.vertexAttribPointer(attributes.position, 2, gl.FLOAT, false, 0, 0);
  gl.uniform2f(uniforms.resolution, window.innerWidth, window.innerHeight);
  gl.uniform1f(uniforms.millis, now);

  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

  requestAnimationFrame(draw);
}

            
          
!
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