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>Town forest starter</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>Town forest starter</h1>
  
  <p>Create a tree composite object and put two copies of it in the town.</p>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                // We always need a scene.
var scene = new THREE.Scene();

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

// complete the createTree() function that creates and returns a THREE.Object3D 
// object that is an instance of a tree, with its origin at the center of the
// base of the trunk

function createTree(trunkRadius, trunkHeight, coneRadius, coneHeight) {



    return tree;
}

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

/* Next, we create objects in our scene. */

var house1 = TW.createMesh( TW.createBarn(2,3,3) );
house1.position.set(4,0,3);
scene.add(house1);

var house2 = TW.createMesh( TW.createBarn(2,3,3) );
house2.position.set(3,0,7);
house2.rotation.y = Math.PI/2;
scene.add(house2);

var house3 = TW.createMesh( TW.createBarn(2,3,3) );
house3.position.set(8,0,5);
house3.rotation.y = -Math.PI/4;
scene.add(house3);

var r3 = 0.5, r2 = r3*0.8, r1 = r2*0.6;
var snow = new THREE.MeshBasicMaterial({color: 0xEEEEEE});

var snow3 = new THREE.Mesh( new THREE.SphereGeometry(r3,30), snow);
var snow2 = new THREE.Mesh( new THREE.SphereGeometry(r2,30), snow);
var snow1 = new THREE.Mesh( new THREE.SphereGeometry(r1,30), snow);

snow3.position.set(3,r3,9);
snow2.position.set(3,r3+r3+r2,9);
snow1.position.set(3,r3+r3+r2+r2+r1,9);

scene.add(snow3);
scene.add(snow2);
scene.add(snow1);

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

// complete and uncomment code to create two instances of a tree, of 
// different size and placed at different positions in the scene

/*
var tree1 = createTree(?, ?, ?, ?);   // your values
tree1.position.set(?, ?, ?);          // your values
scene.add(tree1);

var tree2 = createTree(?, ?, ?, ?);   // your values for big tree
tree2.position.set(?, ?, ?);          // your values
scene.add(tree2);
*/

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

// We always need a renderer

var renderer = new THREE.WebGLRenderer();

TW.mainInit(renderer,scene);

var state = TW.cameraSetup(renderer,
                           scene,
                           {minx: 0, maxx: 12,
                            miny: 0, maxy: 4,
                            minz: 0, maxz: 12});

              
            
!
999px

Console