Skip to content

Instantly share code, notes, and snippets.

@RikusLategan
Created June 6, 2023 07:02
Show Gist options
  • Save RikusLategan/b9b9597731a2eb4ffecbdcec26d35eef to your computer and use it in GitHub Desktop.
Save RikusLategan/b9b9597731a2eb4ffecbdcec26d35eef to your computer and use it in GitHub Desktop.
Untitled

Scratch Paper

Visualize your own code here!

Learning About Tracers

The project Algorithm Visualizer has a visualization library in each supported language (JavaScript , C++, and Java) to visualize codes.

There are five tracers in the library to visualize different types of data:

There are also randomizers to help you create random data.

Check out the API reference for more information.

Making Your Visualization Public

If you think other people would find your visualization useful, you can add it to the side menu by contributing to algorithm-visualizer/algorithms .

https://algorithm-visualizer.org/
// import visualization libraries {
#include "algorithm-visualizer.h"
// }
#include <vector>
#include <string>
// define tracer variables {
Array2DTracer array2dTracer = Array2DTracer("Grid");
LogTracer logTracer = LogTracer("Console");
// }
// define input variables
std::vector<std::string> messages{
"Visuaize",
"your",
"own",
"code",
"here!",
};
// highlight each line of messages recursively
void highlight(int line) {
if (line >= messages.size()) return;
std::string message = messages[line];
// visualize {
logTracer.println(message);
array2dTracer.selectRow(line, 0, message.size() - 1);
Tracer::delay();
array2dTracer.deselectRow(line, 0, message.size() - 1);
// }
highlight(line + 1);
}
int main() {
// visualize {
Layout::setRoot(VerticalLayout({array2dTracer, logTracer}));
array2dTracer.set(messages);
Tracer::delay();
// }
highlight(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment