Skip to content

Instantly share code, notes, and snippets.

@TheoLeanse
Created November 9, 2016 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheoLeanse/f547b1f5ccc53b13875a3e1fda446b1b to your computer and use it in GitHub Desktop.
Save TheoLeanse/f547b1f5ccc53b13875a3e1fda446b1b to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js"></script>
<script>
let container;
let camera, scene, renderer;
init();
animate();
function init () {
container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.y = 200;
camera.position.x = 200;
camera.position.z = 200;
scene = new THREE.Scene();
scene.background = new THREE.Color()
let light, object;
scene.add(new THREE.AmbientLight(0x404040));
light = new THREE.DirectionalLight(0xffffff);
light.position.set(0, 1, 0);
scene.add(light);
let material = new THREE.MeshLambertMaterial();
material.color = new THREE.Color();
object = new THREE.Mesh( new THREE.SphereGeometry( 75, 20, 10 ), material );
object.position.set( 0, 0, 0 );
scene.add( object );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
camera.lookAt( scene.position );
renderer.render( scene, camera );
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment