File tree 1 file changed +39
-3
lines changed
1 file changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -47,13 +47,49 @@ You can use it on [algorithm-visualizer.org](https://algorithm-visualizer.org/)
47
47
## Usage
48
48
49
49
```java
50
+ // import visualization libraries {
50
51
import org.algorithm_visualizer.*;
52
+ // }
51
53
52
54
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
+ }
55
81
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();
57
93
}
58
94
}
59
95
```
You can’t perform that action at this time.
0 commit comments