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() {

  PERCENT = '%';
  NUM = 'num';
  CUBIC = 'cubic';
  QUADRATIC = 'quadratic';
  SMOOTH = 'smooth';
  // this is a speed coded proof of concept which is in the process of
  // being recoded as the api is cleaned up, tested and refined
  var c, sizeType = 'normal', constrained = false,
      s = {
        x: PERCENT,
        y: PERCENT,
        width: PERCENT,
        height: PERCENT,
        radius: PERCENT,
        scale: PERCENT
      },
      s1 = 0xFFFFFF,
      s2 = 0xCCCCCC,
      s3 = 0xFF00FF,
      resolution = 0.01,
      currCurveType = CUBIC;

  width = 0;
  height = 0;
  halfWidth = 0;
  halfHeight = 0;
  mouseX = 0, mouseY = 0;
  animate = true;

  Object.getOwnPropertyNames(Math).forEach(function(name) {
    window[name] = Math[name];
  });

  TWO_PI = PI * 2;
  HALF_PI = PI / 2;
  QUART_PI = HALF_PI / 2;
  RADS = Math.PI / 180;
  DEGS = Math.PI * 180;


  seeds = resetSeeds = function(a, b, c) {
    s1 = a || 0xFFFFFF;
    s2 = b || 0xCCCCCC;
    s3 = c || 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,
        oddNodes= false,
        polyX= [], polyY = [];
    for (var i= 0; i < coords.length; i++){
      polyX[i] = coords[i][0] * size();
      polyY[i] = coords[i][1] * size();
    }

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

  usePercent = function() {
    for (var i in s) s[i] = PERCENT;
  };

  usePixels = usePix = function() {
    for (var i in s) s[i] = NUM;
  };

  sizeFun = null;

  size = function() {
    if (sizeFun) {
      return sizeFun();
    }

    if (sizeType === 'width') {
      return width;
    } else if (sizeType === 'height') {
      return height;
    } else if (sizeType === 'max') {
      // case for useMax?
      return max(width, height);
    }
    return min(width, height);
  };

  sizer = function(f) {
    sizeFun = f;
  };

  useWidth = function() {
    sizeType = 'width';
  };

  useHeight = function() {
    sizeType = 'height';
  };

  useMin = function() {
    sizeType = 'normal';
  };

  useMax = function() {
    sizeType = 'max';
  };

  curveType = function(type) {
    currCurveType = type;
  };

  var curveCubic = function() {
    console.log(arguments);
  };

  curve = function(params, pnts) {
    if (currCurveType === CUBIC) {
      curveCubic(params, pnts);
    } else if (currCurveType === QUADRATIC) {

    } else if (currCurveType === SMOOTH) {

    // see how rapahel and snap do conversion
    } else if (currCurveType === 'catmull?') {

    }

  };

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

  blend = function(mode) {
    context.globalCompositeOperation = mode;
  };

  // this can probably be removed in favor of:
  // `stroke "red"; fill "blue"; etc...
  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 = bg = function(color, alpha) {
    var lastStroke = c.strokeStyle,
        lastFill = c.fillStyle;
    stroke('#000', 0);
    fill(color, alpha);
    rect(0, 0, 1, 1);
    stroke(lastStroke);
    fill(lastFill);
  };

  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)';
  };

  // consider `stroke no`
  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) ? w : width * w;
      h = (s.height === NUM) ? h : height * h;
    } else {
      x = (s.x === NUM) ? x : size() * x;
      y = (s.y === NUM) ? y : size() * y;
      w = (s.width === NUM) ? w : size() * w;
      h = (s.height === NUM) ? h : 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();
  };

  line = function(x1, y1, x2, y2) {
    var scl = size();
    if (!constrained){
      x1 = (s.x === NUM) ? x1 : scl * x1;
      y1 = (s.y === NUM) ? y1 : scl * y1;
      x2 = (s.x === NUM) ? x2 : scl * x2;
      y2 = (s.y === NUM) ? y2 : scl * y2;
    } else {
      x1 = (s.x === NUM) ? x1 : width * x1;
      y1 = (s.y === NUM) ? y1 : height * y1;
      x2 = (s.x === NUM) ? x2 : width * x2;
      y2 = (s.y === NUM) ? y2 : height * y2;
    }
    c.beginPath();
    c.moveTo(x1, y1);
    c.lineTo(x2, y2);
    c.stroke();
  };

  var polygon = function(x, y, verts, close) {
    var data = [];
    c.beginPath();
    for (var i = 0; i < verts.length; i++){
      var x1 = x * width + verts[i][0] * size(),
          y1 = y * height + verts[i][1] * size();
      data[i] = [x1, y1];
      c.lineTo(x1, y1);
    }
    if (close) { c.closePath(); }
    c.fill();
    c.stroke();
    return data;
  };

  poly = function(x, y, verts) {
    return polygon(x, y, verts, true);
  };

  polyline = function(x, y, verts) {
    return polygon(x, y, verts, false);
  };

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

    if (p.range && !Array.isArray(p.range)) {
      p.range = [ 0, p.range ];
    }

    var range = p.range || [0, 1],
        step = p.step || resolution,
        scale = size() * (p.scale || 1),
        sxOff =  xOff,
        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, box, func) {
    if (!box) {
      box = [0, 0, 1, 1];
    }
    var i = 0;
    for (var y = 0; y < rows; y++) {
      for (var x = 0; x < cols; x++) {
        var px = box[0] + (x / (cols - 1)) * box[2],
            py = box[1] + (y / (rows - 1)) * box[3];

        func(px, py, i++, x, y);

      }
    }
  };

  rez = function(val) {
    resolution = val;
  };

  push = save = function() {
    context.save();
  };

  pop = restore = function() {
    context.restore();
  };

  group = function(f) {
    context.save();
    f();
    context.restore();
  };

  trans = translate = function(x, y) {
    x = (s.x === NUM) ? x : width * x;
    y = (s.y === NUM) ? y : height * y;
    context.translate(x, y);
  };

  rotate = function(rot) {
    context.rotate(rot);
  };

  scale = function(x, y) {
    if (arguments.length === 1) {
      context.scale(x, x);
    } else {
      context.scale(x, y);
    }
  };

  window.mobileHack = false;
  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'));
    ctx = context = c = canvas.getContext('2d');

    draw = main;

    if (window.mobileHack === false) {
      // non retina version?
      canvas.setAttribute('style',
                          '-webkit-transform-origin: 0 0; -webkit-transform: scale(0.5);' +
                          '-moz-transform-origin: 0 0; -moz-transform: scale(0.5);' +
                          '-ms-transform-origin: 0 0; -ms-transform: scale(0.5);' +
                          'transform-origin: 0 0; transform: scale(0.5);'
                         );
    }

    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);
      noShadow()

      draw();
    };

    var andDraw = function(loop) {
      render();
      if (animOrMain === true) {
        window.requestAnimationFrame(andDraw, true);
      }
    };

    andDraw(true);

    var resize = function(e) {
      var isPortrait;
      width = window.innerWidth * 2;
      height = window.innerHeight * 2;


      if (isIOS() && window.mobileHack === false) {
        isPortrait = window.innerHeight < window.innerWidth;
        width = window.screen.availWidth * 2;
        height = window.screen.availHeight * 2;

        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();
    };

    if (window.mobileHack ) {
      resize = function() {}
      width = window.innerWidth;
      height = window.innerHeight;
      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