-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoctahedron_image.html
More file actions
147 lines (124 loc) · 5.12 KB
/
Copy pathoctahedron_image.html
File metadata and controls
147 lines (124 loc) · 5.12 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Truncated Octahedron</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 640px;
height: 640px;
background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 100%);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
#canvas-container {
position: relative;
width: 640px;
height: 640px;
background: radial-gradient(circle at 30% 30%, rgba(20, 100, 60, 0.1), transparent 50%),
radial-gradient(circle at center, #0a0e27, #050810);
display: flex;
justify-content: center;
align-items: center;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="canvas-container"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
const container = document.getElementById('canvas-container');
const width = 640;
const height = 640;
const scene = new THREE.Scene();
scene.background = null;
const camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 10000);
camera.position.set(0, 0, 3.5);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(width, height);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
// Minimal lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
scene.add(ambientLight);
// Create proper truncated octahedron
function createTruncatedOctahedron() {
const geometry = new THREE.BufferGeometry();
// 24 vertices of truncated octahedron: all permutations of (0, ±1, ±2)
const verts = [
// (0, 1, 2), (0, 1, -2), (0, -1, 2), (0, -1, -2)
[0, 1, 2], [0, 1, -2], [0, -1, 2], [0, -1, -2],
// (0, 2, 1), (0, 2, -1), (0, -2, 1), (0, -2, -1)
[0, 2, 1], [0, 2, -1], [0, -2, 1], [0, -2, -1],
// (1, 0, 2), (1, 0, -2), (-1, 0, 2), (-1, 0, -2)
[1, 0, 2], [1, 0, -2], [-1, 0, 2], [-1, 0, -2],
// (2, 0, 1), (2, 0, -1), (-2, 0, 1), (-2, 0, -1)
[2, 0, 1], [2, 0, -1], [-2, 0, 1], [-2, 0, -1],
// (1, 2, 0), (1, -2, 0), (-1, 2, 0), (-1, -2, 0)
[1, 2, 0], [1, -2, 0], [-1, 2, 0], [-1, -2, 0],
// (2, 1, 0), (2, -1, 0), (-2, 1, 0), (-2, -1, 0)
[2, 1, 0], [2, -1, 0], [-2, 1, 0], [-2, -1, 0]
];
// Normalize and scale
const vertices = [];
const scale = 0.75;
for (let v of verts) {
const len = Math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
vertices.push(v[0]/len * scale, v[1]/len * scale, v[2]/len * scale);
}
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(vertices), 3));
// Create edges by finding adjacent vertices (distance-based)
const edges = [];
const edgeSet = new Set();
for (let i = 0; i < verts.length; i++) {
for (let j = i + 1; j < verts.length; j++) {
const dx = verts[i][0] - verts[j][0];
const dy = verts[i][1] - verts[j][1];
const dz = verts[i][2] - verts[j][2];
const dist = Math.sqrt(dx*dx + dy*dy + dz*dz);
// Adjacent vertices are at distance sqrt(2)
if (Math.abs(dist - Math.sqrt(2)) < 0.01) {
const key = Math.min(i,j) + "," + Math.max(i,j);
if (!edgeSet.has(key)) {
edgeSet.add(key);
edges.push(i, j);
}
}
}
}
geometry.setIndex(new THREE.BufferAttribute(new Uint16Array(edges), 1));
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x00ff99,
linewidth: 2
});
const lines = new THREE.LineSegments(geometry, lineMaterial);
return lines;
}
const octahedron = createTruncatedOctahedron();
scene.add(octahedron);
// Animation loop
function animate() {
requestAnimationFrame(animate);
octahedron.rotation.x += 0.002;
octahedron.rotation.y += 0.0025;
octahedron.rotation.z += 0.0015;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>