cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div class="collection">
  <a href="https://codepen.io/luigimannoni/pen/xbLgqB" target="_parent" class="prev">&larr; WebGL Soundcloud Visualizer</a>
  <a href="https://codepen.io/luigimannoni/pen/doazmv" target="_parent" class="next">Inside the clock tower &rarr;</a>
  
  
</div>
            
          
!
            
              @import "compass/css3";

body {margin: 0;background-color: #bbb;}
canvas {
  position: absolute; 
  top: 0;left: 0;bottom: 0;right: 0;
  cursor: -webkit-grab; 
  cursor:-moz-grab; 
  &:active { 
    cursor: -webkit-grabbing; 
    cursor:-moz-grabbing;
  }
}

.collection {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 10000;
  a {
    display: block;
    padding: 5px;
    background: rgba(0,0,0,0.6);
    color:#fff;
    text-decoration: none;
    font: 700 12px Consolas, system, monospace;
    @include transition(all 250ms linear);
    &:hover {
      background: #fff;
      color: #000;
    }
  }
  .prev {text-align: left;float: left;}
  .next {text-align: right;float: right;}
}
            
          
!
            
              function deg2rad(_degrees) {
  return (_degrees * Math.PI / 180);
}

var controls;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var innerColor = 0xff0000,
    outerColor = 0xff9900;
var innerSize = 55,
    outerSize = 60;    

var renderer = new THREE.WebGLRenderer();
renderer.setClearColor( 0xbbbbbb, 0 ); // background

renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
controls = new THREE.TrackballControls( camera );
controls.noPan = true;
controls.minDistance = 200;
controls.maxDistance = 650;



// Lights
var light = new THREE.AmbientLight( 0xaaaaaa ); // soft white light
scene.add( light );

var directionalLight = new THREE.PointLight( 0xeeeeee, 1 );
directionalLight.position.set( 0, 0, 0 );
scene.add( directionalLight );

// Core
var core = new THREE.Mesh(
  new THREE.DodecahedronGeometry( innerSize,2 ),
  new THREE.MeshLambertMaterial({ 
    color: 0xf0f0f0,
    ambient: 0xaaaaaa,
    shading: THREE.FlatShading,
    shininess: 40,
  })
);
scene.add(core);

var neutrons = [];

for (var i = 0; i < 2; i++) {
  var group = new THREE.Group();
  scene.add(group);

  // Neutrons
  var neutron = new THREE.Mesh(
    new THREE.DodecahedronGeometry( 12, 2 ),
    new THREE.MeshLambertMaterial({ 
      color: 0xf0f0f0,
      ambient: 0xaaaaaa,
      shading: THREE.FlatShading,
      shininess: 40,
    })
  );
  group.add(neutron);
  neutron.position.x = 200;

  //Ring
  var ring = new THREE.Mesh(
    new THREE.TorusGeometry( 200, 1, 3, 100 ),
    new THREE.MeshBasicMaterial({ 
      color: 0xf0f0f0,
      ambient: 0xaaaaaa,
      shading: THREE.FlatShading,
      shininess: 0,
    })
  );
  group.add(ring);
  
  group.rotation.x = deg2rad(90);
  group.rotation.y = deg2rad(45 * i);
  group.rotation.y -= deg2rad(45/2);
  
  neutrons.push(group);
}

camera.position.z = -320;
controls.target = core.position;

var time = new THREE.Clock();

var render = function () {  
  core.rotation.x += 0.002;

  directionalLight.position.x = Math.cos(time.getElapsedTime()/0.5)*150;
  directionalLight.position.y = Math.cos(time.getElapsedTime()/0.5)*150;
  directionalLight.position.z = Math.sin(time.getElapsedTime()/0.5)*150;

  neutrons[0].rotation.z += 0.005;
  neutrons[1].rotation.z -= 0.005;

  controls.update();
  renderer.render(scene, camera);
  requestAnimationFrame(render);  
};

render();

window.addEventListener('resize', onWindowResize, false);

function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console