body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
30,
window.innerWidth / window.innerHeight,
0.1,
1000
);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// add cube
var geometry = new THREE.BoxGeometry(20, 20, 20);
// use hex string
var color = new THREE.Color("#6f4171");
// use rgba string
var color = new THREE.Color("rgba(188, 141, 190, 1)");
var color = new THREE.Color("#7833aa");
var hex = color.getHex();
var material = new THREE.MeshLambertMaterial({ color: hex });
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// rotate cube
cube.rotation.x = 0.45;
cube.rotation.y = -0.25;
camera.position.z = 100;
var light = new THREE.PointLight(0xffff00);
light.position.set(10, 0, 25);
scene.add(light);
var render = function () {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
render();
This Pen doesn't use any external CSS resources.