Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

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

              
                <html>
  <head>
    
  </head>
  <body>
    <div id="app">
      X: <input v-model.number="rotationSpeed.x" type="range" min="0" max=".5" step=".001"> {{rotationSpeed.x}}
      Y: <input v-model.number="rotationSpeed.y" type="range" min="0" max=".5" step=".001"> {{rotationSpeed.y}}
      Z: <input v-model.number="rotationSpeed.z" type="range" min="0" max=".5" step=".001"> {{rotationSpeed.z}}
      Box Color: <input v-model="boxColor" type="color">
      
      <canvas ref="myCanvas"></canvas>
    </div>
  </body>
</html>
              
            
!

CSS

              
                body{
  margin:0;
  overflow:hidden;
}
canvas{
  background:green;
}
              
            
!

JS

              
                new Vue({
  el: '#app',
  data: {
    renderer: null,
    scene: null,
    camera: null,
    cube: null,
    animationFrame: null,
    backgroundColor: 'gray',
    boxColor: "green",
    rotationSpeed: {
      x: 0.01,
      y: 0.01,
      z: 0.01
    }
  },
  watch: {
    rotationSpeed: {
      handler: function handler(newValue) {

        this.triggerRenderer();
      },
      deep: true
    },
    boxColor: {
      handler(color) {
        this.cube.material.color = new THREE.Color(color)
      }
    }
  },
  methods: {
    triggerRenderer: function triggerRenderer() {
      if (this.animationFrame) {
        cancelAnimationFrame(this.animationFrame);
      }
      this.cube.rotation.x += this.rotationSpeed.x;
      this.cube.rotation.y += this.rotationSpeed.y;
      this.cube.rotation.z += this.rotationSpeed.z;
      this.renderer.render(this.scene, this.camera);

      this.animationFrame = requestAnimationFrame(this.triggerRenderer);
    },
    createGeometry(type = "cube", dimensions = {}, color = 0x000000) {
      const x = dimensions.x || null
      const y = dimensions.y || null
      const z = dimensions.z || null
      var geometry = new THREE.BoxGeometry(x, y, z)
      var material = new THREE.MeshLambertMaterial({
        color: color
      })

      const mesh = new THREE.Mesh(geometry, material);

      return mesh
    }
  },
  mounted: function mounted() {
    // !! continue extracting stuff out to methods and data properties as it makes sense !! //

    // Create the renderer and attach it to the canvas in our document
    this.renderer = new THREE.WebGLRenderer({
      canvas: this.$refs.myCanvas,
      antialias: true
    });

    // add some basic settings to the renderer
    this.renderer.setClearColor(0x00ff00);
    this.renderer.setPixelRatio(window.devicePixelRatio);
    this.renderer.setSize(window.innerWidth, window.innerHeight);

    // Create a perspective camera with the desired view settings
    this.camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 3000);

    // Create the scene that we can start adding stuff to
    this.scene = window.scene = new THREE.Scene();
    this.scene.name = "myscene"

    // create some lights for our scene
    var ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
    ambientLight.name = "ambient light"
    var pointLight = new THREE.PointLight(0xffffff, 0.5);
    pointLight.name = "point light"
    this.scene.add(ambientLight);
    this.scene.add(pointLight);

    this.cube = window.cube = this.createGeometry('cube', {
      x: 100,
      y: 100,
      z: 100
    }, this.boxColor)

    // set the position for the cube
    // note that the z value puts it within our field of view
    this.cube.position.set(0, 0, -500);
    this.cube.name = "the cube!"

    // place that cube
    this.scene.add(this.cube);

    // kick off the animation
    //requestAnimationFrame(this.triggerRenderer)
    this.triggerRenderer();
  }
});
              
            
!
999px

Console