-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviz-temporal.js
More file actions
114 lines (96 loc) · 4.06 KB
/
Copy pathviz-temporal.js
File metadata and controls
114 lines (96 loc) · 4.06 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
export class TemporalVisualization {
constructor() {
this.temporalCoherence = 1.0;
this.timelineRAF = null;
this.probabilityRAF = null;
}
updateTemporalCoherence(coherence) {
this.temporalCoherence = coherence;
}
createTemporalVisualization(futureTimelineContainer, probabilityMatrixContainer) {
if (futureTimelineContainer) {
futureTimelineContainer.innerHTML = '';
this.createTimelineEffect(futureTimelineContainer);
}
if (probabilityMatrixContainer) {
probabilityMatrixContainer.innerHTML = '';
this.createProbabilityEffect(probabilityMatrixContainer);
}
}
createTimelineEffect(container) {
const canvas = document.createElement('canvas');
canvas.width = container.clientWidth;
canvas.height = container.clientHeight;
canvas.style.width = '100%';
canvas.style.height = '100%';
container.appendChild(canvas);
const ctx = canvas.getContext('2d');
const timeNodes = [];
for (let i = 0; i < 5; i++) {
timeNodes.push({
x: (i + 1) * (canvas.width / 6),
y: canvas.height / 2,
radius: 5,
probability: Math.random(),
phase: Math.random() * Math.PI * 2
});
}
const animateTimeline = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const time = Date.now() * 0.001;
ctx.strokeStyle = '#ff6600';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(20, canvas.height / 2);
ctx.lineTo(canvas.width - 20, canvas.height / 2);
ctx.stroke();
const influence = 0.5 + 0.5 * this.temporalCoherence;
timeNodes.forEach((node, index) => {
const pulse = Math.sin(time + node.phase) * 0.5 + 0.5;
const alpha = 0.3 + pulse * 0.7 * influence;
ctx.fillStyle = `rgba(255, 102, 0, ${alpha})`;
ctx.beginPath();
ctx.arc(node.x, node.y + Math.sin(time + index) * 10 * influence,
node.radius * (1 + pulse * 0.5), 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = `rgba(255, 102, 0, ${alpha * 0.5})`;
ctx.lineWidth = 1;
for (let r = 10; r < 50; r += 10) {
ctx.beginPath();
ctx.arc(node.x, node.y, r * pulse * influence, 0, Math.PI * 2);
ctx.stroke();
}
});
this.timelineRAF = requestAnimationFrame(animateTimeline);
};
animateTimeline();
}
createProbabilityEffect(container) {
const canvas = document.createElement('canvas');
canvas.width = container.clientWidth;
canvas.height = container.clientHeight;
canvas.style.width = '100%';
canvas.style.height = '100%';
container.appendChild(canvas);
const ctx = canvas.getContext('2d');
const animateProbability = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const time = Date.now() * 0.001;
const gridSize = 20;
for (let x = 0; x < canvas.width; x += gridSize) {
for (let y = 0; y < canvas.height; y += gridSize) {
const probability = Math.sin(time + x * 0.01 + y * 0.01) * 0.5 + 0.5;
const alpha = probability * 0.5;
ctx.fillStyle = `rgba(255, 102, 0, ${alpha})`;
ctx.fillRect(x, y, 2, 2);
}
}
this.probabilityRAF = requestAnimationFrame(animateProbability);
};
animateProbability();
}
destroy() {
if (this.timelineRAF) cancelAnimationFrame(this.timelineRAF);
if (this.probabilityRAF) cancelAnimationFrame(this.probabilityRAF);
}
}