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>Steeple dat.GUI adjustment final</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>Steeple dat.GUI adjustment final</h1>
  
  <p>Example solution for the steeple adjustment via dat.GUI controls exercise.</p>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                /* Returns a geometry object for a steeple, which is just a square pyramid
 * or tetrahedron.  The origin is in the center of the base, so the base
 * vertices are at y=0 and x and z at plus or minus half the width, and
 * the top is at (0,height,0) */

function createSteeple(width, height) {
    var geom = new THREE.Geometry();
    var w2 = 0.5*width;
    // add the base
    geom.vertices.push(new THREE.Vector3(+w2, 0, +w2));
    geom.vertices.push(new THREE.Vector3(+w2, 0, -w2));
    geom.vertices.push(new THREE.Vector3(-w2, 0, -w2));
    geom.vertices.push(new THREE.Vector3(-w2, 0, +w2));
    geom.vertices.push(new THREE.Vector3(0, height, 0));

    // now that we've got the vertices we need to define the faces.
    // base
    geom.faces.push(new THREE.Face3(0, 1, 2));
    geom.faces.push(new THREE.Face3(0, 2, 3));

    // side faces
    geom.faces.push(new THREE.Face3(0, 1, 4));
    geom.faces.push(new THREE.Face3(1, 2, 4));
    geom.faces.push(new THREE.Face3(2, 3, 4));
    geom.faces.push(new THREE.Face3(3, 0, 4));

    // calculate the normals for shading
    geom.computeFaceNormals();
    geom.computeVertexNormals(true);

    return geom;
}



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

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

var barnWidth = 50;
var barnHeight = 30;
var barnDepth = 40;

var barn1geom = TW.createBarn( barnWidth, barnHeight, barnDepth );
var barn1mesh = TW.createMesh(barn1geom);
scene.add(barn1mesh);

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

var steepleHeight = 36;
var steepleWidth = 6;
var sceneParams = {steepleHeight: steepleHeight};
var steepleMesh;

function placeSteeple(steepleHeight,steepleWidth) {
    var half = steepleWidth * 0.5;
    var steepleGeom = createSteeple(steepleWidth,steepleHeight);
    steepleMesh = TW.createMesh(steepleGeom);
    steepleMesh.position.set(barnWidth*0.5,
                             barnHeight+barnWidth*0.5-half,
                             -half);
    scene.add(steepleMesh);
}

placeSteeple(steepleHeight, steepleWidth);

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

var renderer = new THREE.WebGLRenderer();

TW.mainInit(renderer, scene);

TW.cameraSetup(renderer,
               scene,
               {minx: 0, maxx: barnWidth,
                miny: 0, maxy: barnHeight + barnWidth*0.5+steepleHeight-steepleWidth*0.5,
                minz: -barnDepth, maxz: 0});

function redrawSteeple() {
    scene.remove(steepleMesh);
    steepleHeight++;
    placeSteeple(sceneParams.steepleHeight,steepleWidth);
    TW.render();
}

var gui = new dat.GUI();

gui.add(sceneParams,'steepleHeight',20,40).onChange(redrawSteeple);

              
            
!
999px

Console