cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console