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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                
              
            
!

CSS

              
                html,
body
  margin: 0
  padding: 0
canvas
  display: block
  
  
              
            
!

JS

              
                const noise = new Noise(Math.random())

class Mountain extends THREE.Object3D {
  constructor () {
    super()
    
    this.rotation.x = -Math.PI / 2
    
    this._tX = 0
    this._tZ = 0
    
    // settings
    this.size = 7
    this.resolution = 25  // dont make too high!
    this.height = 1.5
    this.speed = 0.066
    this.flatShading = false
 
    var geom = new THREE.PlaneGeometry(this.size, this.size, this.size * this.resolution, this.size * this.resolution)
    var material = new THREE.MeshLambertMaterial({color:0xff00ff, side: THREE.DoubleSide})
    this.mesh = new THREE.Mesh( geom, material )
   
    this.add(this.mesh)
    
    
    geom.mergeVertices()
    
    const l = geom.vertices.length
    this.originals = []
    for (let i = 0; i < l; i++) {
      const v = geom.vertices[i]

      // store some data associated to it
      this.originals.push({y: v.y,
                       x: v.x,
                       z: v.z
      })
    }
  }
  
  moveWaves () {
    const verts = this.mesh.geometry.vertices
    const l = verts.length

    for (let i = 0; i < l; i++) {
      const v = verts[i]
      const original = this.originals[i]
      
      // need to update Z to go up in Y axis becasue of the rotation on this
      v.z = noise.perlin2(original.x + this._tX, original.y + this._tZ) * this.height
    }

    // Update vertices and comput normals for shading
    this.mesh.geometry.verticesNeedUpdate = true
    if (this.flatShading)
      this.mesh.geometry.computeFlatVertexNormals()
    else
      this.mesh.geometry.computeVertexNormals()
  }
  
  update (delta) {
    this._tX += this.speed * delta
    this._tZ += this.speed * delta

    this.moveWaves()
  }
}
 

/// INIT
let HEIGHT = window.innerHeight
let WIDTH = window.innerWidth

// Create the scene
const scene = new THREE.Scene()

scene.fog = new THREE.Fog(0xc6ccff, 5, 10)

// Create the camera
const aspectRatio = WIDTH / HEIGHT
const fieldOfView = 60
const nearPlane = 0.1
const farPlane = 30
const camera = new THREE.PerspectiveCamera(
  fieldOfView,
  aspectRatio,
  nearPlane,
  farPlane
)

// Create the renderer
const renderer = new THREE.WebGLRenderer({
  alpha: false,
  antialias: true
})

renderer.setPixelRatio(window.devicePixelRatio)
renderer.setClearColor(0xc6ccff, 1)
renderer.setSize(WIDTH, HEIGHT)
document.documentElement.appendChild(renderer.domElement)

const ambientLight = new THREE.AmbientLight(0xffffff, 0.4)
scene.add(ambientLight)
const dirLight = new THREE.DirectionalLight(0xffffff, 0.6)
dirLight.position.set(10, 1, -1)
scene.add(dirLight)


const controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;

function handleWindowResize () {
  // update height and width of the renderer and the camera
  HEIGHT = window.innerHeight
  WIDTH = window.innerWidth
  renderer.setSize(WIDTH, HEIGHT)
  camera.aspect = WIDTH / HEIGHT
  camera.updateProjectionMatrix()
}

const render = () => {
  var delta = clock.getDelta()
  var elapsed = clock.getElapsedTime()
  mountain.update(delta, elapsed)
  controls.update()
  renderer.render(scene, camera)
  window.requestAnimationFrame(render)
}


//////////
// INIT
//////////
window.addEventListener('resize', handleWindowResize, false)

//set camera at eyes height
camera.position.y = 3
camera.position.z = 6
controls.target.set(0, 0, 0)

// create snow
const mountain = new Mountain()
scene.add(mountain)

// start render
const clock = new THREE.Clock()
render()




// DAT GUI
////////////////////////
/*
function add(opt, min, max) {
  return gui.add(snowfall.opts, opt, min, max)
     .onChange(x => snowfall.updateProp(opt))
}

function addColor(opt) {
  return gui.addColor(snowfall.opts, opt)
     .onChange(x => snowfall.updateColor(opt))
}

const gui = new dat.GUI()
add('speedV', 0, 1).step(0.01)
add('speedH', 0, 10).step(0.01)
add('radius', 0, 1).step(0.001)
add('scale', 0, 10).step(0.01)
add('opacity', 0, 1).step(0.01)
addColor('color')
gui.close()

*/
              
            
!
999px

Console