Code Monkey home page Code Monkey logo

codeviz's Introduction

Algorithm visualizer

Path finding

steps:

  1. keep grid in state
  2. get viseted nodes
  3. animate visited node by changing state (one node at time) OR just change style for each visited node (by class name)
  4. get shortest path
  5. animate shortest path in 2 possible way see 3

To fix

  • !IMPORTANT store dom element in Node class instance and use that to change start/end Node and animate
  • file: useGridStore.ts, find better way to reset board an adnimation;
  • file: Visualizer.tsx, find a way to await d.animate() and set to false isRunning

Visulisation aprroaches

/**
 *  APPORACH 1. changes nodes in state and triggers grid rerender (in Node.tsx based on the change the visual change take effect)
 *  i.e. visited nodes get set as visited and on rerender their color becomes blue
 *  less efficient than 2.
 *  more difficult to change based on algorithm
 *  makes more sense cause state grid should reflect algorithm changes in real scenario
 */
// for (let i = 0; i <= visitedNodes.length; i++) {
//   if (i === visitedNodes.length) {
//     for (let y = 0; y <= shortestPath.length; y++) {
//       // add func setNodeToShortesPath
//       setTimeout(() => setNodeToShortesPath(visitedNodes[i]), i * 10);
//     }
//   }
//   setTimeout(() => setNodeToVisited(visitedNodes[i]), i * 10);
// }

// APPROACH 2. grid in state remain the same, elements are changed by changing class in their dom elements (id = "row-col")
// more efficient than 1.
// can change animation depending on algorithm
d.animate(visitedNodes, shortestPath);

codeviz's People

Contributors

fedecech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.