Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
<!doctype html>
<html>
  <head>
    <title>Luxo family</title>
    <style>
      body { max-width: 100%; }
      /* feel free to style the canvas any way you want. If you want it to
      use the entire window, set width: 100% and height: 100%. */
      
      canvas {
          width: 80%;
          height: 500px;
          display: block;
          margin: 10px auto;
      }
    </style>
  </head>
<body>

  <h1>Luxo family</h1>
  
  <p>Using instance transforms to make Luxo and Luxo Jr.</p>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                // create a scene
var scene = new THREE.Scene();

// ====================================================================

var colorMaterials = [new THREE.MeshBasicMaterial({color: new THREE.Color("black"),
                                                   side: THREE.DoubleSide}), 
                      new THREE.MeshBasicMaterial({color: new THREE.Color("white")}),
                      new THREE.MeshBasicMaterial({color: new THREE.Color("brown")})];

// the new luxo() function creates a container object, adds all the meshes
// to this container, and returns the object

function luxo () {
    // create container object
    var lamp = new THREE.Object3D();

    // brown base
    var baseMesh = new THREE.Mesh(new THREE.CylinderGeometry(40,40,8,16),
                                  colorMaterials[2]);
    baseMesh.position.set(0,4,0);
    lamp.add(baseMesh);

    // lower arm
    var armMesh1 = new THREE.Mesh(new THREE.CylinderGeometry(4,4,100), 
                                  colorMaterials[0]);
    armMesh1.position.set(-35,40,0);
    armMesh1.rotation.set(0,0,Math.PI/4);
    lamp.add(armMesh1);

    // upper arm
    var armMesh2 = new THREE.Mesh(new THREE.CylinderGeometry(4,4,100), 
                                  colorMaterials[0]);
    armMesh2.position.set(-35,110,0);
    armMesh2.rotation.set(0,0,-Math.PI/4);
    lamp.add(armMesh2);

    // black cone
    var coneMesh = new THREE.Mesh(new THREE.ConeGeometry(40,80,16,1,true), 
                                  colorMaterials[0]);
    coneMesh.position.set(20,140,0);
    coneMesh.rotation.set(0,0,Math.PI/4);
    lamp.add(coneMesh);

    // lightbulb
    var bulbMesh = new THREE.Mesh(new THREE.SphereGeometry(15), 
                              colorMaterials[1]);
    bulbMesh.position.set(20,140,0);
    lamp.add(bulbMesh);

    return lamp;
}

// create two luxo lamps with the desired position, rotation, and scale
var lamp1 = luxo();
lamp1.position.set(60,0,60);
scene.add(lamp1);

var lamp2 = luxo();
lamp2.position.set(160,0,60);
lamp2.rotation.set(0,Math.PI,0);
lamp2.scale.set(0.5,0.5,0.5);
scene.add(lamp2);

// add a rug to the scene
var rug = new THREE.Mesh(new THREE.PlaneGeometry(200,140),
                         new THREE.MeshBasicMaterial({color: new THREE.Color(TW.GREEN)}));
rug.position.set(100,0,70);
rug.rotation.set(-Math.PI/2,0,0);
scene.add(rug);

// ====================================================================

var renderer = new THREE.WebGLRenderer();

TW.mainInit(renderer,scene);

TW.cameraSetup(renderer,
               scene,
               {minx: 0, maxx: 200,
                miny: 0, maxy: 180,
                minz: 0, maxz: 140});

              
            
!
999px

Console