Videre Splash Visual
by Cody Bennett
CSS
body {
background: #2f2c37;
margin: 0;
overflow: hidden;
}
JavaScript
import * as THREE from 'https://unpkg.com/three/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';
let camera, scene, renderer, controls;
let geometry, material, mesh;
init();
animate();
function createGrid(width = 7, height = 7) {
const grid = new THREE.Group();
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
geometry = new THREE.BoxGeometry(1, 0.5, 0.1);
material = new THREE.MeshBasicMaterial({
color: y === 0 ? 0x25222b : 0x2f2c37
});
mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y / 2, 0);
grid.add(mesh);
material = new THREE.MeshBasicMaterial({
color: 0x636166,
side: THREE.BackSide
});
mesh = new THREE.Mesh(geometry, material);
mesh.scale.multiplyScalar(1.02);
mesh.position.set(x, y / 2, 0);
grid.add(mesh);
}
}
grid.position.x = Math.round(-width + (width / 2));
grid.position.y = -Math.round(height / 6);
grid.rotation.x = 300 * Math.PI / 180;
return grid;
}
function init() {
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 200);
camera.position.z = 3.5;
scene = new THREE.Scene();
const grid = createGrid();
scene.add(grid);
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
controls = new OrbitControls(camera, 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);
controls.update();
render();
}
function render() {
renderer.render(scene, camera);
}