Skip to content

Commit 12fa827

Browse files
authored
Update README.md
1 parent 5cf5fdf commit 12fa827

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

Diff for: README.md

+39-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,49 @@ You can use it on [algorithm-visualizer.org](https://algorithm-visualizer.org/)
4747
## Usage
4848
4949
```java
50+
// import visualization libraries {
5051
import org.algorithm_visualizer.*;
52+
// }
5153
5254
class Main {
53-
public static void main(String[] args) {
54-
LogTracer logTracer = new LogTracer("Scratch Paper");
55+
// define tracer variables {
56+
Array2DTracer array2dTracer = new Array2DTracer("Grid");
57+
LogTracer logTracer = new LogTracer("Console");
58+
// }
59+
60+
// define input variables
61+
String[] messages = {
62+
"Visualize",
63+
"your",
64+
"own",
65+
"code",
66+
"here!",
67+
};
68+
69+
// highlight each line of messages recursively
70+
void highlight(int line) {
71+
if (line >= messages.length) return;
72+
String message = messages[line];
73+
// visualize {
74+
logTracer.println(message);
75+
array2dTracer.selectRow(line, 0, message.length() - 1);
76+
Tracer.delay();
77+
array2dTracer.deselectRow(line, 0, message.length() - 1);
78+
// }
79+
highlight(line + 1);
80+
}
5581
56-
logTracer.print("Visualize your own algorithm here!");
82+
Main() {
83+
// visualize {
84+
Layout.setRoot(new VerticalLayout(new Commander[]{array2dTracer, logTracer}));
85+
array2dTracer.set(messages);
86+
Tracer.delay();
87+
// }
88+
highlight(0);
89+
}
90+
91+
public static void main(String[] args) {
92+
new Main();
5793
}
5894
}
5995
```

0 commit comments

Comments
 (0)