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

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.

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

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

              
            
!

CSS

              
                
              
            
!

JS

              
                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

Console