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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                (function() {
  // this is a speed coded proof of concept which will later be rewritten
  // when a good api is settled upon...
  var c, sizeType = 'normal',
      constrained = false;
  width = 0;
  height = 0;
  halfWidth = 0;
  halfHeight = 0;
  mouseX = 0, mouseY = 0;
  animate = true;
  
  PERCENT = '%';
  NUM = 'num';
  
  var s = {
    x: PERCENT,
    y: PERCENT,
    width: PERCENT,
    height: PERCENT,
    radius: PERCENT,
    scale: PERCENT
  },
      s1 = 0xFFFFFF,
      s2 = 0xCCCCCC,
      s3 = 0xFF00FF,
      resolution = 0.01;
  
  Object.getOwnPropertyNames(Math).forEach(function(name) {
    window[name] = Math[name];
  });
  
  TWO_PI = PI * 2;
  HALF_PI = PI / 2;
  
  resetSeeds = function() {
    s1 = 0xFFFFFF;
    s2 = 0xCCCCCC;
    s3 = 0xFF00FF;
  };
  
  rand = function() {
    var r;
    s1 = ((s1 & 4294967294) << 12) ^ (((s1 << 13) ^ s1) >> 19);
    s2 = ((s2 & 4294967288) << 4) ^ (((s2 << 2) ^ s2) >> 25);
    s3 = ((s3 & 4294967280) << 17) ^ (((s3 << 3) ^ s3) >> 11);
    r = (s1 ^ s2 ^ s3) * 2.3283064365e-10;
    return  r < 0 ? ++r : r;
  };
  
  // needs cleanup
  pointInPoly = function(x, y, coords){
    x *= size();
    y *= size();
    var j = coords.length - 1;
    var oddNodes= false;
    var polyX= [], polyY= [];
    for (var i= 0; i < coords.length; i++){
      polyX[i] = coords[i][0] * size();
      polyY[i] = coords[i][1] * size();
    }
    /*
    c.fillStyle = 'blue';
    c.fillRect(x, y, 10, 10);
   
    c.fillStyle = 'green';
    c.beginPath();
    for (var i = 0; i < coords.length; i++){
      c.lineTo(polyX[i], polyY[i]);
    }
    c.closePath();
    c.fill();
    c.stroke();
   */
    for (var i = 0; i <coords.length; i++) {
    if (polyY[i] <y && polyY[j]>= y ||  polyY[j] <y && polyY[i]>= y) {
      if (polyX[i] + (y - polyY[i]) / (polyY[j] - polyY[i]) * (polyX[j] - polyX[i]) <x) {
        oddNodes = !oddNodes;
      }
    }
    j = i;
  }
  return  oddNodes;
}
  
  units = function(prop, value) {
    s[prop] = value;
    return units;
  };
  
  size = function() {
    if (sizeType === 'width') {
      return width;
    } else if (sizeType === 'height') {
      return height;
    }
    return min(width, height); 
  };
  
  useWidth = function() {
    sizeType = 'width';
  };
  
  useHeight = function() {
    sizeType = 'height';
  };
  
  // case for useMax?
  useMin = function() {
    sizeType = 'normal';
  };
  
  var hexWithAlpha = function(color, alpha) {
     var r, g, b, nColor = '';
    if (typeof color === 'string' && alpha != null) {
      color = color.substr(1);
      if (color.length === 3){
        for (var i = 0; i < 3; i++){
          nColor += color.charAt(i) + color.charAt(i);
        }
        color = nColor;
      }
      color = parseInt(color, 16);
      
      r = color >> 16 & 0xff;
      g = color >> 8 & 0xff;
      b = color & 0xff;
      return [
        'rgba(', r, ',', g, ',', b, ',', alpha, ')'
      ].join('');
    } 
    return color;
  }
  
  fill = function(color, alpha) {
    color = hexWithAlpha(color, alpha);
    c.fillStyle = color;
  };
  
  style = function(p) {
    if (p.stroke) {
      if (p.stroke.length === 2) {
        stroke(p.stroke[0], p.stroke[1]);
      } else {
        stroke(p.stroke);
      }
    }
    
    if (p.fill) {
      if (p.fill.length === 2) {
        fill(p.fill[0], p.fill[1]);
      } else {
        fill(p.fill);
      }
    }
    
    if (p.strokeWidth) {
      strokeWidth(p.strokeWidth);
    }
    
    if (p.shadow) {
      shadow(p.shadow);
    }
    
  };
  
  background = function(color, alpha) {
    var lastStroke = c.strokeStyle;
    stroke('#000', 0);
    fill(color, alpha);
    rect(0, 0, 1, 1);
    stroke(lastStroke);
  };
  
  shadow = function(p) {
    p.color && (c.shadowColor = hexWithAlpha(p.color, p.alpha));
    (p.blur != null) && (c.shadowBlur = p.blur);
    (p.x != null) && (c.shadowOffsetX = p.x * size());
    (p.y != null) && (c.shadowOffsetY = p.y * size());
  };
  
  noShadow = function() {
    c.shadowColor = 'rgba(0,0,0,0)'
  };
  
  stroke = function(color, alpha) {
    color = hexWithAlpha(color, alpha);
    c.strokeStyle = color;
  };
  
  strokeWidth = function(width) {
    c.lineWidth = width;
  };
  
  noFill = function() {
    c.fillStyle = 'rgba(0,0,0,0)';
  };
  
  noStroke = function() {
    c.strokeStyle = 'rgba(0,0,0,0)';
  };
  

  
  constrain = function(val) {
    constrained = val
  },
  
  rect = function(x, y, w, h) {
    if (!constrained){
      x = (s.x === NUM) ? x : width * x;
      y = (s.y === NUM) ? y : height * y;
      w = (s.width === NUM) ? width : width * w;
      h = (s.height === NUM) ? height : height * h;
    } else {
      x = (s.x === NUM) ? x : size() * x;
      y = (s.y === NUM) ? y : size() * y;
      w = (s.width === NUM) ? width : size() * w;
      h = (s.height === NUM) ? height : size() * h;
    }
    c.fillRect(x, y, w, h);
    c.strokeRect(x, y, w, h);
  };
  
  circle = function(x, y, radius) {
    x = (s.x === NUM) ? x : width * x;
    y = (s.y === NUM) ? y : height * y;
    radius = (s.radius === NUM) ? radius : size() * radius;
    c.beginPath();
    c.arc(x, y, radius, 0, PI * 2, false);
    c.fill();
    c.stroke();
  };
  
  poly = function(x, y, verts) {
    var data = [];
    c.beginPath();
    for (var i = 0; i < verts.length; i++){
      var x1 = x * width + verts[i][0] * size();
      var y1 = y * height + verts[i][1] * size();
      data.push([x1, y1]);
      c.lineTo(x1, y1);
    }
    c.closePath();
    c.fill();
    c.stroke();
    return data;
  };
  
  para = parametric = function(xOff, yOff, p) {
    if (arguments.length === 1) {
      var x = (s.x === NUM) ? width / 2 : 0.5,
          y = (s.y === NUM) ? height / 2 : 0.5;
      parametric(x, y, xOff);
      return;
        }
    
    var range = p.range || [0, 1],
        step = p.step || resolution,
        scale = size() * (p.scale || 1);
    var sxOff =  xOff;
    var syOff =  yOff;
    xOff = (s.x === NUM) ? xOff : width * xOff;
    yOff = (s.y === NUM) ? yOff : height * yOff;
    
    if (p.render) {
     
      var verts = [];
      for (var t = range[0]; t <= range[1]; t += step) {
        
        var loc = p.f(t);
        verts.push([loc.x, 
                    loc.y]);
        
      }
      p.render(verts, sxOff, syOff); 
      
    } else 
    if (range[0] < range[1]) {

      c.beginPath();
      
      for (var t = range[0]; t <= range[1]; t += step) {
        
        var loc = p.f(t);
        
        c.lineTo(xOff + loc.x * scale, 
                 yOff + loc.y * scale);
        
      }
      p.close && c.closePath();
      c.fill();
      c.stroke();
    }
    
  };
  
  polar = function(xOff, yOff, p) {
    
    if (arguments.length === 1) {
      var x = (s.x === NUM) ? width / 2 : 0.5,
        y = (s.y === NUM) ? height / 2 : 0.5;
      polar(x, y, xOff);
      return;
        }
    
    var range = p.range || [0, 2 * PI],
        step = p.step || resolution,
        radMult = (p.radius === NUM) ? 1 : size(),
          x, y, r;
    
    xOff = (s.x === NUM) ? xOff : width * xOff;
    yOff = (s.y === NUM) ? yOff : height * yOff;
    
    if (range[0] < range[1]) {
      c.beginPath();
      
      for (var t = range[0]; t <= range[1]; t += step) {
        r = p.radius(t) * radMult;
        x = xOff + r * cos(t);
        y = yOff - r * sin(t);
        c.lineTo(x, y);
        
      }
      (p.close || p.close == undefined) && c.closePath();
      c.fill();
      c.stroke();
    }
    
  };
  
  repeat = function(num, func) {
    var out = true;
    for (var i = 0; i < num; i++){
      if (func(i) === false) {
        out = false;
        break;
      }
    }
    return out;
  };
  
  range = function(start, end, step, func) {
    for (var i = start; i <= end; i += step) {
      func(i); 
    }
  };
  
  grid = function(rows, cols, func) {
    for (var y = 0; y < rows; y++) {
      for (var x = 0; x < cols; x++) {
        
        
        
      } 
    }
  };
  
  rez = function(val) {
    resolution = val;
  };
  
  highrez = function(retina) {
    retina = val;
  };
  
  window.Z = window.z = function(animOrMain, main) {
    
    if (typeof animOrMain !== 'boolean') {
      main = animOrMain
        } 
    
    document.body.setAttribute('style', 'margin: 0; padding; 0; overflow: hidden;');
    
    canvas = document.body.appendChild(document.createElement('canvas'));
    context = c = canvas.getContext('2d');
    
    
    draw = main;
    

    
    var redrawEvent = new Event('redraw');
    
    var ua = window.navigator.userAgent.toLowerCase();
    var isIOS = function() { return /(ipad|iphone)/i.test(ua); };
    var isPad = function() { return /(ipad)/i.test(ua); };
    
    var render = function() {
      strokeWidth(4);
      resetSeeds();
      constrain(false);
      draw();
    };
    var andDraw = function(loop) {
      
      render();
      if (animOrMain === true) {
        window.requestAnimationFrame(andDraw, true); 
      }
    };
    andDraw(true);
    
    if (animOrMain === true) {
      
    }
    
    var resize = function(e) {
      
      width = window.innerWidth  ;
      
      
      height = window.innerHeight  ;
      
      if (isIOS()) {
        width = window.screen.availWidth  ;
        height = window.screen.availHeight ;
   
        var isPortrait = window.innerHeight < window.innerWidth;
        if (isPortrait) {
          var t = width;
          width = height + 40;
          height = t  - (isPad() ? 120 : 0);
        } else {
          height -= 120 - (isPad() ? 30 : 0);
        }
      }
      
      halfWidth = width / 2;
      halfHeight = height / 2;
      
      canvas.width = width;
      canvas.height = height;
      render();
    };
    
    
    window.addEventListener('resize', resize);
    window.addEventListener('orientationchange', resize);
    
    
    document.addEventListener('mousemove', function(e) {
      mouseX = e.pageX * 2;
      mouseY = e.pageY * 2;
    });
    
    
    resize();
  };
  
})();
              
            
!
999px

Console