Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                <script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;

uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;

void main(void) {
  gl_FragColor = vec4(abs(sin(gl_FragCoord.x * 0.1)), abs(sin(time * 0.001)), mouse.x / resolution.x, 1.0);

<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 position;

void main(void) {
  gl_Position = vec4(position, 1.0);
<script src="glsl.js"></script>  
<canvas id="canvas">


                body {
  margin: 0;
  overflow: hidden;



                var canvas;
var gl;

window.onload = function() {
  var fragmentShader, vertexShader;
  var shaderProgram;
  var mouse;
  var startTime;
  var positionAttribute;
  var timeUniformLocatoin, mouseUniformLocation, resolutionUniformLocation;
  var verticesBuffer;
  var vertices;

  canvas = document.getElementById("canvas");
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");

  if (!gl) {
    console.error('can not get context');

  canvas.addEventListener('mousemove', function(e) {
    mouse = [e.offsetX, e.offsetY];
  mouse = [0, 0];
  startTime = new Date().getTime();

  fragmentShader = getShader('shader-fs');
  vertexShader = getShader('shader-vs');
  shaderProgram = gl.createProgram();
  gl.attachShader(shaderProgram, vertexShader);
  gl.attachShader(shaderProgram, fragmentShader);

  if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
    console.error('can not initialize shader program');

  positionAttribute = gl.getAttribLocation(shaderProgram, 'position');

  timeUniformLocatoin = gl.getUniformLocation(shaderProgram, 'time');
  mouseUniformLocation = gl.getUniformLocation(shaderProgram, 'mouse');
  resolutionUniformLocation = gl.getUniformLocation(shaderProgram, 'resolution');

  verticesBuffer = gl.createBuffer();
  gl.bindBuffer(gl.ARRAY_BUFFER, verticesBuffer);
  vertices = [
    1.0, 1.0, 0.0,
    -1.0, 1.0, 0.0,
    1.0, -1.0, 0.0,
    -1.0, -1.0, 0.0
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);

  gl.clearColor(0.0, 0.0, 0.0, 1.0);

  function getShader(id) {
    var shaderScript, shader;

    shaderScript = document.getElementById(id);
    if(!shaderScript) {
      return null;

    if (shaderScript.type == 'x-shader/x-fragment') {
      shader = gl.createShader(gl.FRAGMENT_SHADER);
    } else if (shaderScript.type == 'x-shader/x-vertex') {
      shader = gl.createShader(gl.VERTEX_SHADER);
    } else {
      return null;

    gl.shaderSource(shader, shaderScript.text);

    if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
      console.error('can not comple shader source');
      return null;

    return shader;

  function render() {
    var time, resolution;

    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

    time = (new Date().getTime() - startTime);
    resolution = [canvas.width, canvas.height];
    gl.uniform1f(timeUniformLocatoin, time);
    gl.uniform2fv(mouseUniformLocation, mouse);
    gl.uniform2fv(resolutionUniformLocation, resolution);

    gl.bindBuffer(gl.ARRAY_BUFFER, verticesBuffer);
    gl.vertexAttribPointer(verticesBuffer, 3, gl.FLOAT, false, 0, 0);
    gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

window.onresize = function() {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  gl.viewport(0, 0, canvas.width, canvas.height);