icosa

three.js icosa test

by Nick Hulea

HTML

<script src="http://files.fritzm.org/js/Three.js"></script>
<script src="http://files.fritzm.org/js/RequestAnimationFrame.js"></script>
<div id="container"/>

CSS

body {
    background-color: #000;
}

#container {
    background: #000;
    width: 400px;
    height: 300px;
    margin-left: auto;
    margin-right: auto;
}

JavaScript

var camera, scene, renderer, mesh;

init();
animate();

function init() {

    var WIDTH = 400,
        HEIGHT = 300,
        VIEW_ANGLE = 45,
        ASPECT = WIDTH / HEIGHT,
        NEAR = 0.1,
        FAR = 10000;

    camera = new THREE.Camera(VIEW_ANGLE, ASPECT, NEAR, FAR);
    camera.position.z = 300;

    scene = new THREE.Scene();

    var geometry = new THREE.IcosahedronGeometry(1);

    var material = new THREE.MeshLambertMaterial({
        color: 0xFFFF00,
        shading: THREE.FlatShading
    });

    mesh = new THREE.Mesh(geometry, material);
    mesh.scale = new THREE.Vector3(70, 70, 70);
    scene.addChild(mesh);

    var pointLight = new THREE.PointLight(0xFFFFFF);
    pointLight.position.x = 20;
    pointLight.position.y = 40;
    pointLight.position.z = 130;
    scene.addLight(pointLight);

    var ambientLight = new THREE.AmbientLight(0x202020);
    scene.addLight(ambientLight);

    renderer = new THREE.SVGRenderer();
    renderer.setSize(WIDTH, HEIGHT);
    document.getElementById('container').appendChild(renderer.domElement);

}

function animate() {
    requestAnimationFrame(animate);
    render();
}

function render() {
    mesh.rotation.x += 0.01;
    mesh.rotation.y += 0.02;
    renderer.render(scene, camera);
}