Beispiel #1
0
 /** Draws the state of the game. */
 protected void draw() {
   clear();
   text(0.5, 0.9, label);
   text(0.5, 0.8, textBeingEntered);
   double yDecrement = 0.5 / (game.getRoot().height() + 1);
   drawSubtree(game.getRoot(), 0.5 - yDecrement / 2, yDecrement, 0.0, 1.0);
   show(0);
 }
Beispiel #2
0
 // exchange a[i] and a[j]
 private static void draw(String[] a, int row, int ith, int min) {
   StdDraw.setPenColor(StdDraw.BLACK);
   StdDraw.text(-2.50, row, ith + "");
   StdDraw.text(-1.25, row, min + "");
   for (int i = 0; i < a.length; i++) {
     if (i == min) StdDraw.setPenColor(StdDraw.BOOK_RED);
     else if (i < ith) StdDraw.setPenColor(StdDraw.LIGHT_GRAY);
     else StdDraw.setPenColor(StdDraw.BLACK);
     StdDraw.text(i, row, a[i] + "");
   }
 }
Beispiel #3
0
  // display header
  private static void header(String[] a) {
    int N = a.length;

    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.text(N / 2.0, -3, "a[ ]");
    for (int i = 0; i < N; i++) StdDraw.text(i, -2, i + "");
    StdDraw.text(-2.50, -2, "i");
    StdDraw.text(-1.25, -2, "min");
    StdDraw.setPenColor(StdDraw.BOOK_RED);
    StdDraw.line(-3, -1.65, N - .5, -1.65);
    StdDraw.setPenColor(StdDraw.BLACK);
    for (int i = 0; i < a.length; i++) StdDraw.text(i, -1, a[i]);
  }
Beispiel #4
0
 // display footer
 private static void footer(String[] a) {
   int N = a.length;
   StdDraw.setPenColor(StdDraw.BLACK);
   for (int i = 0; i < a.length; i++) StdDraw.text(i, N, a[i]);
 }