Пример #1
0
  /**
   * Draws the subtree rooted at node.
   *
   * @param y y coordinate at which to draw node.
   * @param yDecrement amount to decrease y coordinate for each level of the tree.
   * @param left left boundary of drawing space for this subtree.
   * @param right right boundary of drawing space for this subtree.
   */
  protected void drawSubtree(Node node, double y, double yDecrement, double left, double right) {
    double mid = (left + right) / 2;
    double leftTip = (mid + left) / 2;
    double rightTip = (mid + right) / 2;
    double bottom = y - yDecrement;

    line(mid, y, leftTip, bottom);
    line(mid, y, rightTip, bottom);

    setPenColor(WHITE);
    filledCircle(mid, y, CIRCLE_RADIUS);
    filledCircle(leftTip, bottom, CIRCLE_RADIUS);
    filledCircle(rightTip, bottom, CIRCLE_RADIUS);

    setPenColor();
    circle(mid, y, CIRCLE_RADIUS);
    circle(leftTip, bottom, CIRCLE_RADIUS);
    circle(rightTip, bottom, CIRCLE_RADIUS);

    if (node == game.getCurrentNode()) {
      setPenColor(RED);
      filledCircle(mid, y, CIRCLE_RADIUS + 0.002);
      setPenColor();
    }

    if (!node.getLeft().isLeaf()) {
      drawSubtree(node.getLeft(), bottom, yDecrement, left, mid);
    } else if (node.getLeft() == game.getCurrentNode()) {
      setPenColor(RED);
      filledCircle(leftTip, bottom, CIRCLE_RADIUS + 0.002);
      setPenColor();
    }

    if (!node.getRight().isLeaf()) {
      drawSubtree(node.getRight(), bottom, yDecrement, mid, right);
    } else if (node.getRight() == game.getCurrentNode()) {
      setPenColor(RED);
      filledCircle(rightTip, bottom, CIRCLE_RADIUS + 0.002);
      setPenColor();
    }
  }