-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviz-neural.js
More file actions
76 lines (62 loc) · 2.37 KB
/
Copy pathviz-neural.js
File metadata and controls
76 lines (62 loc) · 2.37 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
import * as THREE from 'three';
export function createNeuralNetworkVisualization(container, animationFrames, scenes, renderers) {
if (!container) return;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setClearColor(0x000000, 0);
container.appendChild(renderer.domElement);
const nodeGeometry = new THREE.SphereGeometry(0.5, 8, 8);
const nodeMaterial = new THREE.MeshBasicMaterial({
color: 0x0066ff,
transparent: true,
opacity: 0.8
});
const nodes = [];
const connections = [];
for (let layer = 0; layer < 4; layer++) {
const layerNodes = layer === 0 || layer === 3 ? 3 : 5;
for (let i = 0; i < layerNodes; i++) {
const node = new THREE.Mesh(nodeGeometry, nodeMaterial.clone());
node.position.set(
(layer - 1.5) * 4,
(i - layerNodes / 2) * 2,
0
);
nodes.push(node);
scene.add(node);
}
}
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x00ffff,
transparent: true,
opacity: 0.3
});
for (let i = 0; i < nodes.length - 1; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
nodes[i].position,
nodes[i + 1].position
]);
const line = new THREE.Line(geometry, lineMaterial.clone());
connections.push(line);
scene.add(line);
}
camera.position.z = 15;
const animate = () => {
nodes.forEach((node, index) => {
const time = Date.now() * 0.001;
node.material.opacity = 0.5 + 0.3 * Math.sin(time + index * 0.5);
node.scale.setScalar(0.8 + 0.2 * Math.sin(time * 2 + index));
});
connections.forEach((connection, index) => {
const time = Date.now() * 0.001;
connection.material.opacity = 0.1 + 0.2 * Math.sin(time + index * 0.3);
});
renderer.render(scene, camera);
animationFrames.set('neural', requestAnimationFrame(animate));
};
animate();
scenes.set('neural', scene);
renderers.set('neural', renderer);
}