-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.js
More file actions
151 lines (134 loc) · 4.24 KB
/
state.js
File metadata and controls
151 lines (134 loc) · 4.24 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
148
149
150
151
const appState = {
layers: [],
activeLayerIndex: -1
};
let history = [];
function saveState() {
// Deep copy the current state for undo
history.push(JSON.parse(JSON.stringify(appState)));
if (history.length > 20) history.shift();
}
function undo() {
if (history.length > 1) {
history.pop();
const lastState = history[history.length - 1];
appState.layers = JSON.parse(JSON.stringify(lastState.layers));
appState.activeLayerIndex = lastState.activeLayerIndex;
updateUIFromState();
drawComposition();
}
}
function reset() {
appState.layers = [
{
id: Date.now().toString(),
type: 'Original Spiral',
visualizer: window.Visualizers.Spiral,
params: window.Visualizers.Spiral.getDefaultParams()
}
];
appState.activeLayerIndex = 0;
// Reset Master settings
document.getElementById('autoRotate').checked = false;
document.getElementById('audioReactive').checked = false;
document.getElementById('audioRotate').checked = false;
document.getElementById('audioScale').checked = false;
document.getElementById('audioOpacity').checked = false;
document.getElementById('audioLineWidth').checked = false;
history = [];
updateLayerListUI();
updateUIFromState();
drawComposition();
}
function getActiveLayer() {
if (appState.activeLayerIndex >= 0 && appState.activeLayerIndex < appState.layers.length) {
return appState.layers[appState.activeLayerIndex];
}
return null;
}
function addLayer(type) {
saveState();
let visualizer = null;
if (type === 'Original Spiral') {
visualizer = window.Visualizers.Spiral;
} else if (type === 'Fractal') {
visualizer = window.Visualizers.Fractal;
}
if (visualizer) {
appState.layers.push({
id: Date.now().toString() + Math.random().toString(36).substr(2, 5),
type: type,
visualizer: visualizer,
params: visualizer.getDefaultParams()
});
appState.activeLayerIndex = appState.layers.length - 1;
updateLayerListUI();
updateUIFromState();
drawComposition();
}
}
function removeActiveLayer() {
if (appState.layers.length > 1 && appState.activeLayerIndex >= 0) {
saveState();
appState.layers.splice(appState.activeLayerIndex, 1);
appState.activeLayerIndex = Math.max(0, appState.activeLayerIndex - 1);
updateLayerListUI();
updateUIFromState();
drawComposition();
}
}
function updateLayerListUI() {
const layerList = document.getElementById('layerList');
if(!layerList) return;
layerList.innerHTML = '';
appState.layers.forEach((layer, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = `[Layer ${index + 1}] ${layer.type}`;
if (index === appState.activeLayerIndex) {
option.selected = true;
}
layerList.appendChild(option);
});
}
function updateUIFromState() {
const activeLayer = getActiveLayer();
if (!activeLayer) return;
const spiralControls = document.getElementById('spiralControlsContainer');
const fractalControls = document.getElementById('fractalControlsContainer');
if (spiralControls && fractalControls) {
if (activeLayer.type === 'Fractal') {
spiralControls.style.display = 'none';
fractalControls.style.display = 'block';
} else {
spiralControls.style.display = 'block';
fractalControls.style.display = 'none';
}
}
const params = activeLayer.params;
Object.keys(params).forEach(key => {
const el = document.getElementById(key);
if (el) {
if (el.type === 'checkbox') el.checked = params[key];
else el.value = params[key];
const valueSpan = document.getElementById(key + 'Value');
if (valueSpan) {
valueSpan.textContent = (el.type === 'range' && el.step.includes('.')) ? parseFloat(params[key]).toFixed(1) : params[key];
}
}
});
// Base values for audio fallback are now layer-specific, we'll store them back to the UI globally for simplicity
window.baseScale = params.scale;
window.baseLineWidth = params.lineWidth;
}
// Global master audio settings (not layer specific for now)
let masterAudioParams = {
autoRotate: false,
audioReactive: false,
audioRotate: false,
audioScale: false,
audioLineWidth: false,
audioOpacity: false,
scaleGap: 10,
scaleSensitivity: 1
};