Pen Settings



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


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


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.


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.


                <!doctype html>

  <title>Snowman angled</title>
    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: 800px;
      height: 500px;
      display: block;
      margin: 10px auto;


  <h1>Snowman angled</h1>

  <p>View of snowman created by changing Vup.</p>






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

// ====================================================================
// New tree function

function createTree(trunkRadius, trunkHeight, coneRadius, coneHeight) {
    // returns a mesh object, with origin at the center of the base of the
    // trunk.
    var tree = new THREE.Object3D();
    var cone = new THREE.Mesh( new THREE.ConeGeometry(coneRadius,coneHeight),
                               new THREE.MeshBasicMaterial({color: THREE.ColorKeywords.darkgreen}));
    cone.position.y = coneHeight/2+trunkHeight;
    var trunk = new THREE.Mesh( new THREE.CylinderGeometry(trunkRadius,trunkRadius,trunkHeight),
                                new THREE.MeshBasicMaterial({color: THREE.ColorKeywords.brown}));
    trunk.position.y = trunkHeight/2;
    return tree;

// ====================================================================
// copied from SnowPerson-composite-v2.shtml

function createSnowPerson (wireframe, radiusBottom, radiusMiddle, radiusTop, carrotLength) {
    /* Returns a three-sphere snowperson. The args are the radii of the
    spheres, starting from the bottom, and the length of the carrot. The
    snowperson sits on the origin, and the spheres are stacked along the y
    axis. There's an orange cone (carrot) for a nose */

    // these could also be parameters
    var bodyColor = THREE.ColorKeywords.white;
    var bodyMaterial = new THREE.MeshBasicMaterial({color: bodyColor});
    bodyMaterial.wireframe = wireframe;
    var sphereDetail = 10;
    var carrotColor =;

    // here is our container
    var frosty = new THREE.Object3D();

    // function to add one snowball to frosty.  
    // height is distance of origin to sphere center along y.
    function addSphere(radius,height) {
        var sg = new THREE.SphereGeometry(radius,sphereDetail,sphereDetail);
        var s = new THREE.Mesh(sg, bodyMaterial);
        console.log("adding sphere: "+radius+" at "+height);
        s.position.y = height;   // specify where along Y to add it

    // ================================================================
    // main code of function
    var y = radiusBottom;  // center of bottom sphere
    y += radiusBottom + radiusMiddle;  // center of middle sphere
    y += radiusMiddle + radiusTop;  // center of top sphere
    // add the carrot
    var carrotGeom = new THREE.CylinderGeometry(radiusTop/5, 0, carrotLength);
    var carrotMesh = new THREE.Mesh( carrotGeom, 
                                     new THREE.MeshBasicMaterial({color: carrotColor}));
    carrotMesh.position.set(0, y, radiusTop+carrotLength/2);
    carrotMesh.rotation.x = -1 * Math.PI/2;
    return frosty;

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

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

var house1 = TW.createMesh( TW.createBarn(2,3,3) );

var house2 = TW.createMesh( TW.createBarn(2,3,3) );
house2.rotation.y = Math.PI/2;

var house3 = TW.createMesh( TW.createBarn(2,3,3) );
house3.rotation.y = -Math.PI/4;

var tree1 = createTree(0.2,1,2,6);

var tree2 = createTree(0.3,1.5,3,8); // big tree

var r3=0.5, r2=r3*0.8, r1=r2*0.6;
var smx = 3, smz = 9;           // snowman x and z

var snowman = createSnowPerson(false,r3,r2,r1,0.2);

// add a red wireframe box around the snowman's head

var boxGeom = new THREE.BoxGeometry(2*r1, 2*r1, 2*r1);
var boxMesh = new THREE.Mesh(boxGeom, 
                     new THREE.MeshBasicMaterial( {color:,
                                                   wireframe: true} ));
boxMesh.position.set(3, r3+r3+r2+r2+r1, 9);

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

// object to store the desired camera parameters

var cameraParams = {
    near: 0.1,        // reduced, to see things very close to camera
    far: 100,
    fov: 75,                // degrees
    aspectRatio: 1000/600,   // from dimensions of the canvas, see CSS
    atX: 3,
    atY: r3+r3+r2+r2+r1,
    atZ: 9,           
    eyeX: 3,         // camera positioned close to snowman's head
    eyeY: r3+r3+r2+r2+r1,
    eyeZ: 14,
    upX: -1,         // adjust the direction of Vup
    upY: 1,
    upZ: 0

// setupCamera() function creates and returns a camera with the desired parameters

function setupCamera (cameraParameters) {
    // set up an abbreviation 
    var cp = cameraParameters;
    // create an initial camera with the desired shape
    var camera = new THREE.PerspectiveCamera(cp.fov, cp.aspectRatio, cp.near, cp.far);
    // set the camera location and orientation
    camera.position.set(cp.eyeX, cp.eyeY, cp.eyeZ);
    camera.up.set(cp.upX, cp.upY, cp.upZ);
    camera.lookAt(new THREE.Vector3(cp.atX, cp.atY, cp.atZ));
    return camera;

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

// We always need a renderer

var renderer = new THREE.WebGLRenderer();


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

// create camera, add to scene, and render scene with new camera

var camera = setupCamera(cameraParams);

function render() {
    // a render function; assume global variables scene, renderer, and camera