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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="space" class="space"></div>
<!--
M51 was recorded by Lord Rosse in 1845.
Lord Rosse’s 72-inch telescope enabled him to see the spiral shape of the M51 nebula. Like many astronomers, he drew the bright parts of the image with a dark pencil, making his drawing look like a photographic negative.
!-->

              
            
!

CSS

              
                html {
  overflow: hidden;
  background: hsla(0, 0%, 0%, 1);
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-image: radial-gradient(top, circle cover, hsla(330, 90%, 15%, 1) 20%, hsla(0, 0%, 0%, 1) 80%);
cursor:move;
}

body,
.space {
  width: 100%;
  margin: 0;
  overflow: hidden;
}

#space {
  left: 0;
  top: 0;
  zoom: 1
}

#space span {
  position: absolute;
}
              
            
!

JS

              
                var _3DPretty = function() {
var obj = [],
    _x = 0,
    _y = 0,
    _x1 = 0,
    _y1 = 0,
    parts = 500,
    $, _tx, _ty, _w, _h;

  var resize = function() {
    _w = window.innerWidth * 0.5;
    _h = window.innerHeight * 0.5;
  }
  var set = function(n, f) {
    if (!!n) parts = n;
    $ = document.getElementById('space');
    window.addEventListener('mousemove', function(e) {
      _x = e.clientX;
      _y = e.clientY;
    });
    window.addEventListener('touchmove', function(e) {
      e.preventDefault();
      _x = e.touches[0].clientX;
      _y = e.touches[0].clientY;
    });
    resize();
    window.addEventListener('resize', resize);
    _set(f);
    run();
  }
  var run = function() {
    window.requestAnimationFrame(run);
    anime();
  }
  var _set = function(f) {
    for (var i = 0; i < parts; i++) {
      var o = {};
      o.p = document.createElement('span');
      $.appendChild(o.p);
      var r = i / parts, j, a, b;
      j = i % (parts * .5);
      a = Math.floor(j) / 100 + (Math.floor(j / 2) % 10) / 5 * Math.PI * 2;
      b = Math.acos(-0.9 + (j % 4) * 0.6);
      r = !!f ? f(r) : r - r * r + .5;
      var sbr = Math.sin(b) * r;
      o.x = Math.sin(a) * sbr;
      o.y = Math.cos(a) * sbr;
      o.z = Math.cos(b) * r;
      obj.push(o);
      o.transform = function() {
      var ax = .02 * _tx,
          ay = .02 * _ty,
          cx = Math.cos(ax),
          sx = Math.sin(ax),
          cy = Math.cos(ay),
          sy = Math.sin(ay);

      var z = this.y * sx + this.z * cx;
          this.y = this.y * cx + this.z * -sx;
          this.z = this.x * -sy + z * cy;
          this.x = this.x * cy + z * sy;

       var sc = 1 / (1 + this.z),
            x = this.x * sc * _h + _w - sc * 2,
            y = this.y * sc * _h + _h - sc * 2;

        var p = this.p.style;
        if (x >= 0 && y >= 0 && x < _w * 2 && y < _h * 2) {
          var c = Math.round(256 + (-this.z * 256));
          p.left = Math.round(x) + 'px';
          p.top = Math.round(y) + 'px';
          p.width = Math.round(sc * 2) + 'px';
          p.height = Math.round(sc * 2) + 'px';
          p.background = 'hsla(' + y + ',80%,80%,1)';
          p.zIndex = 200 + Math.floor(-this.z * 100);
        } else p.width = "0px";
      }
    }
  }
  var anime = function() {
    var se = 1 / _h;
    _tx = (_y - _x1) * se;
    _ty = (_x - _y1) * se;
    _x1 += _tx;
    _y1 += _ty;
    for (var i = 0, o; o = obj[i]; i++) o.transform();
  }
  return {
    set: set
  }
}();
window.onload = function() {
  _3DPretty.set(500, function(r) {
    return r * r;
  });
}
              
            
!
999px

Console