A(lgorithm)Anim(ation) is a library for creating 3b1b-ish videos on visulizing data structure and algorithms.
-
pip3: You need to update pip3 to the latest version.
-
ManimCE: We use ManimCE (instead of ManimGL) to make animations. Follow this tutorial.
-
manim_fonts: Run
pip3 install manim_fontsto install manim fonts. -
Graphviz: If you are generating graph algorithms (vs. heap), you will need to install graphviz. Simply run
brew install graphviz -
Clone this repo to your local environment. Make sure you are on the main branch.
After cloned the repo, cd source and try python3 -m manim graph.py Test -ql, if you see a video generated in a few seconds, you are good to go.
You will need to cd source first. I made a video explaining what AAnim is in details. Starting at 4:02 there is a demo on how users interact with the tool to give you a more concrete idea of how it works. The instructions below are equivalent.
Heap operations that we currently support are build a heap, insert, and delete. Use the following default command to try: python3 animate_heap.py command_heap.txt
You can also customize your command in command_heap.txt. Please follow the following format strictly. It can take any combination of the following four commands:
- Create a heap by giving a list of numbers less than 15 elements, seperated by space. This command always need to be the first one and no duplicates. For example:
19 18 17 16 15 14 13 12 11 - Build a heap: build [min/max]. For example:
build min - Extract the Min/Max: extract.
- Insert a value and heapify: insert [integer]. For example:
insert 1
We use the layout engine from Graphviz to get an optimized layout of a graph so you don't have to input the layout information.
-
Create a
.gvfile that describes all edges of the graph that you want to create. An example isgraph_blueprint.gv. You need to follow the exact format to list out each edge as below:- 1a) For an un-weighted undirected graph:
graph G { # You can't modify the first line A -- B # Use A -- B to represent an undirected edge B -- C # Indentation is allowed but not encouraged C -- A C -- D Z # An isolated node } # You can't modify the last line- 1b) For an un-weighted directed graph:
digraph G { # Use digraph instead of graph A -> B # Use A -> B to represent a directed edge. B -> C C -> A C -> D }- 1c) For a weighted unidrected graph:
graph G { A -- B [xlabel=4] # Add [xlabel=your_weight] at the end, the weight should be an integer B -- C [xlabel=5] C -- A [xlabel=2] C -- D [xlabel=3] } -
Enter your command on termimal. The format of the command is:
python3 animate_graph.py [a) .gv file] [b) an algorithm] [c) source node]. For example,python3 animate_graph.py graph_blueprint.gv prim.- 2a) [.gv file]: Required. The name of the .gv file you just created in step 1.
- 2b) [an algorithm]: Required. The name of the algorithm you want to run on this graph. You can choose one from:
bfs, trypython3 animate_graph.py graph_blueprint4.gv bfs Adfs, trypython3 animate_graph.py graph_blueprint4.gv dfs Aprim-basic, trypython3 animate_graph.py graph_blueprint3.gv prim-basicprim, trypython3 animate_graph.py graph_blueprint3.gv primkruskal-basic, trypython3 animate_graph.py graph_blueprint3.gv kruskal-basickruskal, trypython3 animate_graph.py graph_blueprint3.gv kruskaldijkstra, trypython3 animate_graph.py graph_blueprint6.gv dijkstra Abellmanford, trypython3 animate_graph.py graph_blueprint6.gv bellmanford A
- 2c) [source node]: Optional. If you choose
bfs,dfs,dijkstraorbellmanford, this argument is required. If you choosekruskal-basicorkruskal, the argument is not allowed. For other algorithms, the argument is optional.
A image, output.png, will be generated in about 3 seconds in source directory just in case you are curious what the graph look like after position being calculated.
Normally a video of 100 animations would take around 6 mins to generate. It's not fast so be patient :)
- We are working on an web version of AAnim.
- We are working on dynamically placing the graph and the code such that they won't overlap.
- We are working on a new feature to give you freedom to choose different layout of the graph by specifying a layout engine among
dot,neato,twopi,circo,fdp,osage,sfdp.
The above instructions were tested only on Mac OS X Intel version. Feel free to give it a try anyway and let me know if it doesn't work on your env and we can figure it out together. We thank you for choosing AAnim! If you have any suggestions or comments, feel free to contact Joy: zhuozhuo530[at]gmail.