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

              
                <link href="https://fonts.googleapis.com/css?family=Fira+Mono" rel="stylesheet">

<div id="content">
  <h1>THE MOON</h1>
  <h2>Map of impact craters at least 40 km in diameter</h2>
  <div id="scene"></div>
</div>
              
            
!

CSS

              
                html, body {
  height: 100%;
  width: 100%;
}

body {
  background-color: #222222;
  text-align: center;
  color: #ffffff;
  font-family: 'Fira Mono', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  letter-spacing: .1em;
}

h1, h2 {
  font-size: 1rem;
}

h2 {
  color: #aaaaaa;
  font-weight: normal;
}

#scene {
  width: 400px;
  height: 400px;
  margin: auto;
}

#scene canvas {
  cursor: -webkit-grab;
  cursor: -moz-grab;
}

#scene canvas:active {
  cursor: -webkit-grabbing;
  cursor: -moz-grabbing;
}
              
            
!

JS

              
                var scene, renderer, camera, controls, moonDisc, craters, outline;

var WIDTH = 400,
    HEIGHT = 400,
    PIXEL_RATIO = window.devicePixelRatio || 1;

var radius = 10,
    moonRadius = 1737,
    scaleRatio = radius / moonRadius,
    bgColor = 0x222222;

function initScene() {
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(15, 1, .1, 2000);
  camera.position.z = 100;

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setClearColor( bgColor );
  renderer.setPixelRatio( PIXEL_RATIO );
  renderer.setSize( WIDTH, HEIGHT );

  container = document.getElementById( 'scene' );
  container.appendChild( renderer.domElement );

  controls = new THREE.OrbitControls( camera, renderer.domElement );
  controls.enableZoom = false;
  controls.enablePan = false;
  controls.enableDamping = true;
  controls.dampingFactor = 0.2;
  controls.autoRotate = true;
  controls.autoRotateSpeed = 0.5;
  controls.rotateSpeed = 0.15;

  // Build scene objects
  material = new THREE.LineBasicMaterial( { color: bgColor, linewidth: 2 } ),
  geometry = new THREE.CircleGeometry( radius, 100 );

  moonDisc = new THREE.Mesh( geometry, material );
  scene.add( moonDisc );

  // var outline = new THREE.EdgesHelper( moonDisc, 0xffffff );
  // outline.material.linewidth = 3;
  // scene.add( outline );
  
  resolution = new THREE.Vector2( WIDTH, HEIGHT );
  var line = new MeshLine();
  var curve = new THREE.EllipseCurve( 0, 0, radius, radius, 0, 2*Math.PI, false, 0 );
  var path = new THREE.Path( curve.getPoints( 100 ) );
  var outlineGeometry = path.createPointsGeometry( 50 );
  line.setGeometry( outlineGeometry );
  	var material = new MeshLineMaterial( {
		useMap: false,
		opacity: 1,
		resolution: resolution,
		sizeAttenuation: !false,
		lineWidth: 0.8,
		near: camera.near,
		far: camera.far
	});
  outline = new THREE.Mesh( line.geometry, material );
  scene.add( outline )

  craters = createCraters();
  scene.add( craters );

  loop();
}

function createCraters() {
  var container = new THREE.Object3D();
  var material = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 1 } );

  for (var i = 0; i < craterData.length; i++) {
    var crater = craterData[i];
    var r = crater.diam/2 * scaleRatio;
    var samplePoints = Math.floor(Math.sqrt(r)*20);
    var zOffset = Math.sqrt(radius*radius - r*r);

    var curve = new THREE.EllipseCurve(0, 0, r, r, 0, 2 * Math.PI, false);
    var path = new THREE.Path( curve.getPoints( samplePoints ) );
    var geometry = path.createPointsGeometry( samplePoints );
    geometry.translate(0, 0, zOffset);

    geometry.rotateX(-crater.lat*THREE.Math.DEG2RAD);
    geometry.rotateY(crater.lon*THREE.Math.DEG2RAD);

    var crater = new THREE.Line( geometry, material );
    container.add( crater );
  }

  return container;
}

function loop() {
  controls.update();
  moonDisc.lookAt( camera.position );
  outline.lookAt( camera.position );
  //craters.rotation.y += 0.005;

  renderer.render(scene, camera);

  requestAnimationFrame(loop);
}

initScene();

              
            
!
999px

Console