three.js ~ example ~ Mr.doob

2012-01-05 ~

by intrinsica

JavaScript

var camera, scene, renderer, geometry, material, mesh1;

init();
animate();

function init() {

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.z = 500;
    scene.add(camera);

    renderer = new THREE.CanvasRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);

    document.body.appendChild(renderer.domElement);

    // create a canvas element
    var canvas1 = document.createElement('canvas');
    var context1 = canvas1.getContext('2d');
    context1.font = "40px Verdana";
    context1.fillStyle = "rgba(0,0,0,1)";
    context1.fillText("|||||||||||||||||||||||||||||", 0, 40);

    // canvas contents will be used for a texture
    var texture1 = new THREE.Texture(canvas1);
    texture1.needsUpdate = true;

    var material1 = new THREE.MeshBasicMaterial({ map: texture1, side: THREE.DoubleSide });
    material1.transparent = true;

    mesh1 = new THREE.Mesh(
        new THREE.PlaneGeometry(canvas1.width, canvas1.height),
        material1
        );
    scene.add(mesh1);
}

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

function render() {
    mesh1.rotation.x += 0.001;
    mesh1.rotation.y += 0.002;

    renderer.render(scene, camera);
}