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.

            
              <script src="https://wzrd.in/standalone/resl@latest"></script>
<script src="https://wzrd.in/standalone/regl@latest"></script>
<script src="https://wzrd.in/standalone/fail-nicely@latest"></script>
<script src="https://wzrd.in/standalone/control-panel@latest"></script>

            
          
!
            
              regl({
  pixelRatio: 1,
  attributes: {antialias: false, depth: false, alpha: false},
  onDone: failNicely(regl => resl({
    manifest: {
      bg: {
        src: 'https://s3.amazonaws.com/rickyreusser.com/nzca-2014/canz-20-half.jpg',
        parser: img => regl.texture({data: img, flipY: true}),
        type: 'image'
      }
    },
    onDone: ({bg}) => run(regl, bg)
  }))
});

function run (regl, bg) {
  // A nice control panel to control the opacity.
  var config = {alpha: 1.0};
  controlPanel([
    {type: 'range', min: 0, max: 1, label: 'alpha', initial: config.alpha},
  ]).on('input', function (data) {
    config.alpha = data.alpha;
  });
  
  // A function to scale content to either css-style contain or cover. It accepts a reference shape
  // so that it can just be a scale *relative* to some other shape (the background image, in particular).
// Type is either 'contain' or 'cover'.
  function createScale (type, refShape) {
    refShape = refShape || [1, 1];
    var multiplier = type === 'cover' ? 1 : -1;
    return function (ctx) {
      var viewAR = ctx.framebufferWidth / ctx.framebufferHeight;
      var imageAR = refShape[0] / refShape[1];
      return multiplier * viewAR > multiplier * imageAR ? [1, imageAR / viewAR] : [viewAR / imageAR, 1];
    }
  }
  
  const drawBg = regl({
    vert: `
      precision lowp float;
      attribute vec2 xy;
      uniform vec2 scale;
      varying vec2 uv;
      void main () {
        uv = 0.5 * xy * scale + 0.5;
        gl_Position = vec4(xy, 0, 1);
      }
    `,
    frag: `
      precision lowp float;
      uniform sampler2D src;
      varying vec2 uv;
      void main () {
        gl_FragColor = texture2D(src, uv);
      }
    `,
    uniforms: {
      scale: createScale('cover', [bg.width, bg.height]),
      src: bg,
    },
    attributes: {xy: [-4, -4, 0, 4, 4, -4]},
    depth: {enable: false},
    count: 3
  });
  
  const drawPoints = regl({
    vert: `
      precision lowp float;
      attribute float s, phase;
      attribute vec4 color;
      uniform vec2 scale;
      uniform float t, pointSize;
      varying vec4 c;
      void main () {
        c = color;
        vec2 xy = vec2(cos(s + t), sin(s + t)) * cos(t + s * 0.41);
        gl_Position = vec4(xy / scale, 0, 1);
        gl_PointSize = pointSize;
      }
    `,
    frag: `
      precision lowp float;
      uniform float alpha;
      varying vec4 c;
      void main () {
        vec2 uv = gl_PointCoord - 0.5;
        
        // make a rough circle:
        if (dot(uv, uv) > 0.25) discard;

        // premultiplying the alpha like this means we can use *just* the multiplicative
        // part of the blending function (src * dst). But alpha = 0 corresponds to
        // multiplying by one, so we have to do this little 'one minus' trick:
        gl_FragColor = vec4(1.0 - alpha * (1.0 - c.rgb), 1);
      }
    `,
    attributes: {
      s: [0, 1.05, 2.09, 3.14, 4.19, 5.24],
      color: [[1, 0, 0, 1], [1, 1, 0, 1], [0, 1, 0, 1], [0, 1, 1, 1], [0, 0, 1, 1], [1, 0, 1, 1]]
    },
    blend: {
      enable: true,
      func: {
        // This says use src * dst to get the result:
        srcRGB: 'dst color',
        srcAlpha: 1,
        // this part discards *adding* the second part since the dst color
        // was already used above:
        dstRGB: 0,
        dstAlpha: 1
      },
      equation: {
        rgb: 'add',
        alpha: 'add'
      },
    },
    depth: {enable: false},
    uniforms: {
      scale: createScale('contain'),
      alpha: () => config.alpha,
      t: regl.context('time'),
      pointSize: () => Math.min(regl.limits.pointSizeDims[1], Math.min(window.innerWidth, window.innerHeight) / 3)
    },
    primitive: 'points',
    count: 6
  });
  
  regl.frame(() => {
    drawBg();
    drawPoints();
  });
}
            
          
!
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