Code
Three.js
Hello Cube
Scene, PerspectiveCamera, WebGLRenderer, and a rotating cube — the Three.js hello-world.
Geometries
Six built-in geometries (Box, Sphere, Cone, Cylinder, Torus, Icosahedron) spinning with MeshNormalMaterial.
Materials
Basic, Normal, Lambert, Phong, and Standard materials compared side-by-side on identical spheres.
Lighting
Three coloured PointLights orbiting a white PBR sphere — AmbientLight, PointLight, and dynamic colour mixing.
Animation
Three objects animating with independent rotation, vertical sine oscillation, and pulse scaling.
Particle System
3 000 particles in a BufferGeometry — each bouncing inside a volume, uploaded to the GPU every frame.
Shader Material
Custom GLSL vertex and fragment shaders — sine-wave vertex displacement with animated RGB colour cycling.
Generative Art
Noise-displaced icosphere with per-vertex colour cycling — organic 3D generative art from layered trig noise.
Hello Cube
Beginner The Three.js hello-world — a scene, PerspectiveCamera, WebGLRenderer, and a rotating cube with MeshNormalMaterial. Three.js Docs
import * as THREE from 'three';
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1a1a2e);
const camera = new THREE.PerspectiveCamera(60, W / H, 0.1, 100);
camera.position.set(0, 0, 3);
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setSize(W, H);
const geometry = new THREE.BoxGeometry(1.2, 1.2, 1.2);
const material = new THREE.MeshNormalMaterial();
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
function animate() {
cube.rotation.x += 0.008;
cube.rotation.y += 0.012;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();