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

              
                <!-- Quick start template: https://codepen.io/pen/?template=ZEyrWNe -->

<canvas id="canvas"></canvas>
<div>
  <h1>Gloopy Border</h1>
  <p>A GLSL shader made with Inigo Quilez's 3D Perlin noise function.</p>
  <label for="thickness">Thickness</label>
  <input type="range" id="thickness" name="thickness" min="0" max="50" value="25" step="0.1">
  <label for="intensity">Intensity</label>
  <input type="range" id="intensity" name="intensity" min="0" max="10" value="5" step="0.1">
  <label for="noise">Noise</label>
  <input type="range" id="noise" name="noise" min="0" max="50" value="20" step="0.1">
</div>

<script id="vertexShader" type="x-shader/x-vertex">
  attribute vec4 position;

  void main() {
    gl_Position = vec4( position );
  }
</script>

<script id="fragmentShader" type="x-shader/x-fragment">
  #ifdef GL_FRAGMENT_PRECISION_HIGH
  precision highp float;
  #else
  precision mediump float;
  #endif

  uniform vec2 u_resolution;
  uniform float u_time;
  uniform vec2 u_mouse;
  uniform float u_thickness;
  uniform float u_intensity;
  uniform float u_noise;
  
  //3D Gradient Noise by Inigo Quilez - iq/2013
  //https://www.shadertoy.com/view/Xsl3Dl
  vec3 hash( vec3 p ) // replace this by something better
  {
    p = vec3( dot(p,vec3(127.1,311.7, 74.7)),
          dot(p,vec3(269.5,183.3,246.1)),
          dot(p,vec3(113.5,271.9,124.6)));

    return -1.0 + 2.0*fract(sin(p)*43758.5453123);
  }

  float noise( in vec3 p )
  {
    vec3 i = floor( p );
    vec3 f = fract( p );
	
	  vec3 u = f*f*(3.0-2.0*f);

    return mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), 
                          dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),
                     mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), 
                          dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),
                mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), 
                          dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),
                     mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), 
                          dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z );
  }

  void main() {
    float borderWidth = u_thickness;
    
    float halfWidth = u_resolution.x * 0.5;
    float halfHeight = u_resolution.y * 0.5;
    
    float xv = abs(gl_FragCoord.x - halfWidth) - halfWidth + borderWidth;
    float yv = abs(gl_FragCoord.y - halfHeight) - halfHeight + borderWidth;
    
    xv /= borderWidth;
    yv /= borderWidth;
    
    float r = max(yv, xv);
    
    vec2 uv = gl_FragCoord.xy / u_resolution;
    //Smoothly extend on the x axis without stretching the noise
    uv.x *= u_resolution.x/u_resolution.y;
    uv *= u_noise;
    float n = noise( vec3(uv.x, uv.y, u_time / 2.0));
    r += n;
    r *= u_intensity;
    
    gl_FragColor = vec4( 0.0, 0.0, 0.0, r );
  }
</script>
              
            
!

CSS

              
                body {
 margin: 0;
}

div {
  margin: 80px;
}

p {
  font-size: 22px;
}

label {
  font-size: 22px;
  font-weight: bold;
  display: block;
}

input {
  display: block;
  margin-bottom: 10px;
  width: 100%;
  max-width: 300px;
}

canvas {
 position: fixed;
 pointer-events: none;
 top: 0;
 left: 0;
 width: 100vw;
 height: 100vh;
}
              
            
!

JS

              
                // Following the twgl tiny tutorial, https://twgljs.org/
// Code adapted from https://github.com/greggman/twgl.js/blob/master/examples/tiny.html

const gl = document.getElementById("canvas").getContext("webgl");
const programInfo = twgl.createProgramInfo(gl, ["vertexShader", "fragmentShader"]);

const arrays = {
  position: [-1, -1, 0, 1, -1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1, 1, 0],
};
const bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);

const thicknessSlider = document.getElementById("thickness");
const intensitySlider = document.getElementById("intensity");
const noiseSlider = document.getElementById("noise");

let mouseX = 0, mouseY = 0;

document.getElementById("canvas").addEventListener('mousemove', e => {
  mouseX = e.clientX;
  mouseY = e.clientY;
});


function render(time) {
  //Paints only 25% pixels in the screen space, 
  //Slightly lower resolution but much better performance!
  //See also: the zoom feature of https://glslsandbox.com/
  
  //twgl.resizeCanvasToDisplaySize(gl.canvas, 0.5); 
  
  //Paints 4x the number of pixels.
  //Very computationally expensive in full screen on desktop devices
  twgl.resizeCanvasToDisplaySize(gl.canvas, 0.5); 

  gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);

  const uniforms = {
    u_time: (time) * 0.002,
    u_resolution: [gl.canvas.width, gl.canvas.height],
    u_mouse: [mouseX, mouseY],
    u_thickness: thicknessSlider.value,
    u_intensity: intensitySlider.value,
    u_noise: noiseSlider.value,
  };

  gl.useProgram(programInfo.program);
  twgl.setBuffersAndAttributes(gl, programInfo, bufferInfo);
  twgl.setUniforms(programInfo, uniforms);
  twgl.drawBufferInfo(gl, bufferInfo);

  requestAnimationFrame(render);
}
requestAnimationFrame(render);
              
            
!
999px

Console