Skip to content

Commit 3a2b926

Browse files
Add speed modulation
1 parent 6d62c37 commit 3a2b926

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/code/js/animation.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ function generateAnimations({ element }) {
2323
} else {
2424
for (let elem of pathElements) {
2525
// console.log('animate', elem);
26-
switch (elem.type) {
26+
switch (elem.element.type) {
2727
case 'userInput':
28-
generateUserInputAnimation(elem);
28+
generateUserInputAnimation(elem.element);
2929
break;
3030
case 'lut':
31-
generateLUTAnimation(elem);
31+
generateLUTAnimation(elem.element);
3232
break;
3333
case 'DFF':
34-
generateDFFAnimation(elem);
34+
generateDFFAnimation(elem.element);
3535
break;
3636

3737
default:
@@ -99,7 +99,7 @@ async function move(element, distances) {
9999
if (index >= steps.length) return;
100100

101101
element.animate([steps[index]], {
102-
duration: speedValue,
102+
duration: speedValue / speedLevelsInt[currentSpeedIndex],
103103
fill: 'forwards'
104104
}).onfinish = () => {
105105
// Apply styles to maintain position
@@ -150,9 +150,9 @@ async function animatePath(i) {
150150
}
151151

152152
if (isPaused) return;
153-
154-
let type = pathElements[i].type;
155-
let id = pathElements[i].id;
153+
let type = pathElements[i].element.type;
154+
let id = pathElements[i].element.id;
155+
console.log('type :', type, 'id :', id);
156156
if (type == "DFF") type = "ff";
157157

158158
let elem = document.getElementById(`animation-${type}-${id}`);
@@ -167,10 +167,13 @@ async function animatePath(i) {
167167
let wiresLength = wire4 != null
168168
? (wire5 != null ? 5 : 4)
169169
: 3;
170+
171+
speedValue = pathElements[i].Timing != null ? pathElements[i].Timing * 5 / wiresLength: 2000;
170172

171173
animateElement(elem, [wire1, wire2, wire3, wire4, wire5]);
172174

173175
setTimeout(() => {
176+
console.log('element', pathElements[i]);
174177
if (i < pathElements.length - 2) {
175178
elem.remove();
176179
generateAnimations({ element: elem });
@@ -181,5 +184,5 @@ async function animatePath(i) {
181184
play.firstChild.className = 'fa-solid top-bar fa-circle-play';
182185
isPaused = true;
183186
}
184-
}, wiresLength * speedValue);
187+
}, speedValue * wiresLength / speedLevelsInt[currentSpeedIndex]);
185188
}

src/code/js/parse-json-to-data.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
function sortElements(luts, flipFlops, ios, connections) {
2-
let UI = connections.find(connection => { return connection.Input.type === 'userInput' });
2+
let timing;
3+
let UI = connections.find(connection => {
4+
timing = connection.Timing;
5+
return connection.Input.type === 'userInput'
6+
});
37
let UIIndex = connections.indexOf(UI);
48

5-
pathElements.push(UI.Input);
9+
pathElements.push({ element: UI.Input, Timing: timing });
610

711
displayInput(UI.Input.type);
812
let currentElement = connections[UIIndex].Output;
@@ -23,11 +27,12 @@ function sortElements(luts, flipFlops, ios, connections) {
2327
let ff = flipFlops.find(ff => { return ff.id.toString() === currentElement.id });
2428
displayFlipFlop(ff.id, ff.connections[0].id, ff.connections[1].id, ff.connections[2].id);
2529
}
26-
27-
pathElements.push(currentElement);
30+
31+
pathElements.push({ element: currentElement, Timing: timing });
2832
if (connections.find(connection => connection.Output.type === 'userOutput')) {
2933
while (currentElement.type != 'userOutput') {
3034
let nextElement = connections.find(connection => {
35+
timing = connection.Timing;
3136
return (connection.Input.type === currentElement.type && connection.Input.id === currentElement.id)
3237
}).Output;
3338

@@ -45,7 +50,7 @@ function sortElements(luts, flipFlops, ios, connections) {
4550
}
4651

4752
currentElement = nextElement;
48-
pathElements.push(currentElement);
53+
pathElements.push({ element: currentElement, Timing: timing });
4954
}
5055
}
5156

src/code/js/variables.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const zoomLevels = ["25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%"]
1010
let currentZoomIndex= 3;
1111

1212
const speedLevels = ["x0.5", "x1", "x2", "x4", "x8", "x16", "x32"];
13+
const speedLevelsInt = [.5, 1, 2, 4, 8, 16, 32];
1314
let currentSpeedIndex= 1;
1415

15-
const speedValue = 200;
16+
let speedValue;
1617

1718
let currentTheme = "dark";
1819

0 commit comments

Comments
 (0)