-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathttt3d.html
60 lines (52 loc) · 1.7 KB
/
ttt3d.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Stunning Tic-Tac-Toe</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
let camera, scene, renderer;
let boardCells = [];
init();
animate();
function init() {
const sceneWidth = window.innerWidth;
const sceneHeight = window.innerHeight;
const cellSize = 100;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, sceneWidth / sceneHeight, 0.1, 1000);
camera.position.z = 5;
renderer = new THREE.WebGLRenderer();
renderer.setSize(sceneWidth, sceneHeight);
document.body.appendChild(renderer.domElement);
// Create the Tic-Tac-Toe board
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 3; col++) {
const cellGeometry = new THREE.BoxGeometry(cellSize, cellSize, cellSize);
const cellMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, wireframe: true });
const cell = new THREE.Mesh(cellGeometry, cellMaterial);
cell.position.set(col * cellSize - cellSize, row * cellSize - cellSize, 0);
scene.add(cell);
boardCells.push(cell);
}
}
// Add lights to the scene
const ambientLight = new THREE.AmbientLight(0x404040);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff);
pointLight.position.set(5, 5, 5);
scene.add(pointLight);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
</script>
</body>
</html>