From 5b42362d8c7be3355d123fcf4412e62290ae22a6 Mon Sep 17 00:00:00 2001 From: Stepan Susorov <137768644+Ba6ySHark@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:18:27 -0600 Subject: [PATCH] Patch 10 --- src/App.css | 42 +++++++++++++++++++++++++++++++++++++++- src/App.js | 29 ++++++++++++++++++++++----- src/algorithms/bfs.js | 6 +++--- src/algorithms/dfs.js | 6 +++--- src/components/NavBar.js | 22 ++++++++++++++++----- 5 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/App.css b/src/App.css index 6697151..c42aba3 100644 --- a/src/App.css +++ b/src/App.css @@ -26,7 +26,7 @@ body { z-index: 999; } -.features--algos { +.featured--algos { display: block; } @@ -50,6 +50,46 @@ body { position: absolute; display: block; } + +.speed--settings { + display: block; +} + +.speed--settings:hover { + .speeds--list { + position: absolute; + display: block; + margin: 0; + } +} + +.speed--settings h3 { + line-height: 50px; +} + +.speeds--list { + display: none; +} + +.wall--patterns { + display: block; +} + +.wall--patterns:hover { + .patterns--list { + position: absolute; + display: block; + margin: 0; + } +} + +.wall--patterns h3 { + line-height: 50px; +} + +.patterns--list { + display: none; +} /* nav section ends here */ .canvas { diff --git a/src/App.js b/src/App.js index d8a3f28..98114bf 100644 --- a/src/App.js +++ b/src/App.js @@ -9,6 +9,8 @@ import dfsAlgorithm from "./algorithms/dfs.js"; export default function App() { let [featured_algorithm, setFeaturedAlgorithm] = React.useState("Dijkstra"); + let [animationSpeed, setAnimationSpeed] = React.useState(25); // in ms (fast by default) + const rows = (window.innerHeight / 20) / (1.5); const columns = ((window.screen.width - 150) / 20); @@ -83,7 +85,7 @@ export default function App() { } newList[path_node.row][path_node.column] = newNode; setNodes(newList); - }, (25 * i)); + }, (animationSpeed * i)); } } @@ -92,7 +94,7 @@ export default function App() { if (i === path.length) { setTimeout(() => { animatePath(createPath(endNode), nodes, setNodes); - }, 25 * i); + }, animationSpeed * i); } else { setTimeout(() => { @@ -105,7 +107,7 @@ export default function App() { newList[node.row][node.column] = newNode; setNodes(newList); //console.log(newList); - }, (25 * i)); + }, (animationSpeed * i)); } }; }; @@ -132,8 +134,8 @@ export default function App() { } function visualizeDFS(nodes, setNodes) { - const startNode = nodes[8][40]; - const endNode = nodes[8][10]; + const startNode = nodes[8][10]; + const endNode = nodes[8][40]; const path = dfsAlgorithm(nodes, startNode, endNode); animateAlgorithm(path, nodes, endNode, setNodes); } @@ -144,6 +146,21 @@ export default function App() { console.log(featured_algorithm); }; + function selectAnimationSpeed(value) { + if (value === "fast") { + setAnimationSpeed(25); + } + else if (value === "average") { + setAnimationSpeed(50); + } + else if (value === "slow") { + setAnimationSpeed(100); + } + else { + console.log("Error: unknown animation speed parameter"); + } + } + function visualizeSelectedAlgorithm() { if (featured_algorithm === "Dijkstra") { visualizeDijkstra(nodes, setNodes); @@ -182,6 +199,8 @@ export default function App() {