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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              window.onload = function(){
  
  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
   
  var renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
 
  renderer.setClearColorHex(0x000000); 
 
  var groundTex = THREE.ImageUtils.loadTexture( "https://s3-us-west-2.amazonaws.com/s.cdpn.io/96252/space-backdrop7.jpg" ); 
  
  var groundGeo = new THREE.PlaneGeometry(1000,500,1,1);
  var groundMat = new THREE.MeshBasicMaterial({color:0xffffff, map:groundTex});
  var ground = new THREE.Mesh(groundGeo,groundMat);
  scene.add(ground);
  
  var planet2RingGeo = new THREE.TorusGeometry( 9, 1.5, 16, 100 );
  var planet2RingMesh = new THREE.MeshPhongMaterial( {color: 0x8e3131} ); 
  var planet2Ring = new THREE.Mesh( planet2RingGeo, planet2RingMesh ); 
  scene.add( planet2Ring );
  
  var planet7RingGeo = new THREE.TorusGeometry( 9, 0.3, 16, 100 );
  var planet7RingMesh = new THREE.MeshPhongMaterial( {color: 0x78a0bc} ); 
  var planet7Ring = new THREE.Mesh( planet7RingGeo, planet7RingMesh ); 
  scene.add( planet7Ring );
  
  function planet(size,step,stepIncrement,orbitDist,emissiveCol,tex){
    
        var loadtex = THREE.ImageUtils.loadTexture( "https://s3-us-west-2.amazonaws.com/s.cdpn.io/96252/" + tex ); 
        loadtex.wrapS = THREE.RepeatWrapping; 
        loadtex.wrapT = THREE.RepeatWrapping; 
        loadtex.repeat.set( 4, 3 ); 
    
        this.size = size;
        this.step = step;
        this.orbitDist = orbitDist;
        this.stepIncrement = stepIncrement;  
        this.emissiveCol = emissiveCol;
        this.geometry = new THREE.SphereGeometry( this.size, 32, 32 );
        this.mesh = new THREE.MeshPhongMaterial( {color: 0xffffff, map: loadtex, emissive: this.emissiveCol} ); 
        this.planet = new THREE.Mesh( this.geometry, this.mesh ); 
        scene.add( this.planet );
  }

  var sun = new planet(19,0,0,0,0xffe400,"sun.jpg");
  var planet2 = new planet(5,0,0.005,35,0x000000,"redplanet.jpg");
  var planet3 = new planet(1,3,0.015,50,0x000000,"blorgn.jpg");
  var planet4 = new planet(1.5,2,0.01,65,0x000000,"netra.jpg");
  var planet5 = new planet(5,2,0.006,80,0x000000,"arrothus.jpg");
  var planet5Moon = new planet(1,2.5,0.05,80,0x000000,"arrothus.jpg");
  var planet6 = new planet(1.5,3,0.01,95,0x000000,"fallnic.jpg");
  var planet7 = new planet(6,3.5,0.004,110,0x000000,"jaranon.jpg");
  var planet8 = new planet(5,0.6,0.006,135,0x000000,"saldoard.jpg");
  var planet8Moon1 = new planet(1,2.5,0.05,80,0x000000,"saldoard.jpg");
  var planet8Moon2 = new planet(1,0,0.04,80,0x000000,"blorgn.jpg");
  var planet9 = new planet(1.5,0.6,0.005,165,0x000000,"u4.jpg");
  
  var totalPlanets = [planet2,planet3,planet4,planet5,planet6,planet7,planet8,planet9]
  
  sun.planet.position.x = 140; 
  sun.planet.position.y = 0; 
  sun.planet.position.z = -150; 

  planet2Ring.rotation.x = -1.57;
  planet2Ring.scale.z = 0.1;
  
  planet7Ring.rotation.x = -1.57;
  planet7Ring.scale.z = 0.3;
  
  ground.position.x = 140; 
  ground.position.y = -10; 
  ground.position.z = -400; 
  
  camera.position.z = 30; 
  camera.position.x = 110;
  camera.position.y = 12; 
  camera.rotation.x = -0.1; 
  camera.rotation.z = -0.1; 
  
  var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 ); 
  directionalLight.position.set( -300, 10,-200 ); 
  scene.add( directionalLight );
  
  var pointLight = new THREE.PointLight( 0xffffff, 1.5, 900 );
  scene.add(pointLight);

  var step = 0;
  
  var clock = new THREE.Clock();

  var renderPass = new THREE.RenderPass(scene, camera);
  var effectCopy = new THREE.ShaderPass(THREE.CopyShader);
  effectCopy.renderToScreen = true;
  var bloomPass = new THREE.BloomPass(1, 20, 14.0, 128);

  var composer = new THREE.EffectComposer(renderer);
  composer.addPass(renderPass);
  composer.addPass(effectCopy)

  var renderScene = new THREE.TexturePass(composer.renderTarget2);

  var composer3 = new THREE.EffectComposer(renderer);
  composer3.addPass(renderScene);
  composer3.addPass(bloomPass);
  composer3.addPass(effectCopy);
  
  render();
  
  function render(){
    var delta = clock.getDelta();
    
    requestAnimationFrame(render);
   
    renderer.autoClear = false;
    renderer.clear();
    composer.render(delta);
    composer3.render(delta);
    
    for(var x=0; x < totalPlanets.length; x++){
      totalPlanets[x].step += totalPlanets[x].stepIncrement; 
      totalPlanets[x].planet.position.z = -150 +( totalPlanets[x].orbitDist*(Math.cos(totalPlanets[x].step)));
      totalPlanets[x].planet.position.x = 140 +( totalPlanets[x].orbitDist*(Math.sin(totalPlanets[x].step)));
    }
    
    planet2Ring.position.z = -150 +( planet2.orbitDist*(Math.cos(planet2.step)));
    planet2Ring.position.x = 140 +( planet2.orbitDist*(Math.sin(planet2.step)));
    
    planet7Ring.position.z = -150 +( planet7.orbitDist*(Math.cos(planet7.step)));
    planet7Ring.position.x = 140 +( planet7.orbitDist*(Math.sin(planet7.step)));

    planet5Moon.step += planet5Moon.stepIncrement;
    planet5Moon.planet.position.z = planet5.planet.position.z +( 10*(Math.cos(planet5Moon.step)));
    planet5Moon.planet.position.x = planet5.planet.position.x +( 10*(Math.sin(planet5Moon.step)));
    
    planet8Moon1.step += planet8Moon1.stepIncrement;
    planet8Moon1.planet.position.z = planet8.planet.position.z +( 10*(Math.cos(planet8Moon1.step)));
    planet8Moon1.planet.position.x = planet8.planet.position.x +( 10*(Math.sin(planet8Moon1.step)));
    
    planet8Moon2.step += planet8Moon2.stepIncrement;
    planet8Moon2.planet.position.z = planet8.planet.position.z +( 15*(Math.cos(planet8Moon2.step)));
    planet8Moon2.planet.position.x = planet8.planet.position.x +( 15*(Math.sin(planet8Moon2.step)));
    
    sun.planet.rotation.y += 0.005;
    
    pointLight.position.set(140,0,-150);
  };

 var webglOutput = document.getElementById("WebGL-output");
  webglOutput.appendChild(renderer.domElement);

}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console