示例#1
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
示例#2
0
  /** By Dingding */
  private Set<Line.Segment> getRemovableLineSegments(
      Map<Position, Piece> pieceMap, PieceColor pieceColor) {
    Set<Line.Segment> removableLines = new HashSet<>();
    Set<Line> linesOnTheBoard =
        Line.getLinesOnTheBoard(
            this); // Get all the possible lines on the board. Positions don't need to be occupied.

    for (Line line : linesOnTheBoard) {
      Position currentPosition = line.getStartPosition();
      Position startOfSegment = null;
      Position endOfSegment = null;
      Direction direction = line.getDirection();
      int consecutivePieces =
          0; // We start at a dot position, so we can assume that we don't start in a set of
             // consecutive pieces
      boolean isInLineSegment = false;

      // Break the for-loop if an endOfSegment has been found (because the largest lines only have 7
      // positions on the board, there
      // can't be more than one set of four pieces of the same color (requiring at least 9
      // positions) on the board.
      for (;
          endOfSegment == null && isPositionOnPlayAreaOrOuterDots(currentPosition);
          currentPosition = currentPosition.next(direction)) {
        PieceColor currentPieceColor =
            pieceMap.containsKey(currentPosition)
                ? pieceMap.get(currentPosition).getPieceColor()
                : null;

        // Update the consecutivePieces
        if (currentPieceColor == pieceColor) consecutivePieces++;
        if (consecutivePieces == 4) isInLineSegment = true;
        if (currentPieceColor != pieceColor) consecutivePieces = 0;

        if (isInLineSegment) {
          if (isDotPosition(currentPosition) || currentPieceColor == null) {
            endOfSegment = currentPosition.previous(direction);
          }
        }

        // Update the startOfSegment if necessary
        if (startOfSegment == null) {
          if (currentPieceColor != null) {
            startOfSegment = currentPosition;
          }
        }
        if (currentPieceColor == null && endOfSegment == null) {
          startOfSegment = null;
        }

        // Add a line segment to the list if we have found one
        if (endOfSegment != null) {
          removableLines.add(new Line.Segment(this, startOfSegment, endOfSegment, direction));
        }
      }
    }

    return removableLines;
  }
示例#3
0
 /**
  * Draws a Line object on the GrapherPanel as a 1 pixel wide line ending on the points defining
  * the Line object.
  *
  * @param The Line to paint.
  */
 private void paintLine(Line l) {
   g.setColor(Color.YELLOW);
   g.drawLine(
       250 + (int) (l.getPointA().getX() * 25),
       250 - (int) (l.getPointA().getY() * 25),
       250 + (int) (l.getPointB().getX() * 25),
       250 - (int) (l.getPointB().getY() * 25));
 }
示例#4
0
 /**
  * Draws a Polygon object on the GrapherPanel as a series of 1 pixel wide lines contained in the
  * polygon's sides variable.
  *
  * @param The Polygon to paint.
  */
 private void paintPolygon(Polygon p) {
   g.setColor(Color.GREEN);
   for (Line l : p.getSides()) {
     g.drawLine(
         250 + (int) (l.getPointA().getX() * 25),
         250 - (int) (l.getPointA().getY() * 25),
         250 + (int) (l.getPointB().getX() * 25),
         250 - (int) (l.getPointB().getY() * 25));
   }
 }
示例#5
0
 /**
  * Draws a Triangle object on the GrapherPanel as a series of 1 pixel wide lines contained in the
  * Triangle's sides variable.
  *
  * @param The Triangle to paint.
  */
 private void paintTriangle(Triangle t) {
   g.setColor(Color.GREEN);
   for (Line l : t.getSides()) {
     g.drawLine(
         250 + (int) (l.getPointA().getX() * 25),
         250 - (int) (l.getPointA().getY() * 25),
         250 + (int) (l.getPointB().getX() * 25),
         250 - (int) (l.getPointB().getY() * 25));
   }
 }
  public void changeColor() {

    // set initial color of top left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.cyan);
    }
    // set initial color of top right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.magenta);
    }
    // set initial color of bottom left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.yellow);
    }
    // set initial color of bottom right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.black);
    }
  }
  private void mixerComboBoxActionPerformed() {
    Mixer mixer = AudioSystem.getMixer((Mixer.Info) mixerComboBox.getSelectedItem());

    Line.Info lineInfo = mixer.getSourceLineInfo(new Line.Info(Clip.class))[0];

    boolean volumeSupported;
    boolean panSupported;

    try {
      Line line = mixer.getLine(lineInfo);

      volumeSupported = line.isControlSupported(FloatControl.Type.MASTER_GAIN);
      panSupported = line.isControlSupported(FloatControl.Type.PAN);
    } catch (LineUnavailableException e) {
      volumeSupported = false;
      panSupported = false;
    }

    enableMixerVolumeCheckBox.setEnabled(volumeSupported);
    enableMixerPanCheckBox.setEnabled(panSupported);
  }
示例#8
0
  private ArrayList<RSTile> generatePath(Line[] lines) {
    double minStep = 5, maxStep = 10, wander = 3;
    if (lines.length < 2) return null;
    ArrayList<RSTile> path = new ArrayList<RSTile>();
    Line l1, l2 = lines[0];
    double distFromCenter = random(0, l2.getDistance() + 1);
    RSTile p = l2.translate((int) distFromCenter);
    distFromCenter = l2.getDistance() / 2 - distFromCenter;
    double centerXdist, centerYdist, line1Xdist, line1Ydist, line2Xdist, line2Ydist;
    double line1dist, line2dist, centerDist;
    double x, y;
    double distOnLine, last, cap1, cap2, move;
    double distFromCenterX1, distFromCenterY1, distFromCenterX2, distFromCenterY2;
    double force1, force2, slopeX, slopeY, slopeDist;
    boolean finished;
    int lastX = p.getX(), lastY = p.getY(), curX, curY;
    double dist, xdist, ydist;
    for (int i = 1; i < lines.length; i++) {
      l1 = l2;
      l2 = lines[i];
      centerXdist = l2.getCenterX() - l1.getCenterX();
      centerYdist = l2.getCenterY() - l1.getCenterY();
      centerDist = Math.sqrt(centerXdist * centerXdist + centerYdist * centerYdist);
      line1Xdist = l2.getX() - l1.getX();
      line1Ydist = l2.getY() - l1.getY();
      line2Xdist = l2.getX2() - l1.getX2();
      line2Ydist = l2.getY2() - l1.getY2();

      centerXdist /= centerDist;
      centerYdist /= centerDist;
      line1Xdist /= centerDist;
      line1Ydist /= centerDist;
      line2Xdist /= centerDist;
      line2Ydist /= centerDist;
      distOnLine = 0;
      last = 0;
      finished = false;
      while (!finished) {

        distOnLine += random(minStep, maxStep);
        if (distOnLine >= centerDist) {
          distOnLine = centerDist;
          finished = true;
        }
        x = centerXdist * distOnLine + l1.getCenterX();
        y = centerYdist * distOnLine + l1.getCenterY();

        distFromCenterX1 = x - (line1Xdist * distOnLine + l1.getX());
        distFromCenterY1 = y - (line1Ydist * distOnLine + l1.getY());

        distFromCenterX2 = x - (line2Xdist * distOnLine + l1.getX2());
        distFromCenterY2 = y - (line2Ydist * distOnLine + l1.getY2());

        slopeX = distFromCenterX2 - distFromCenterX1;
        slopeY = distFromCenterY2 - distFromCenterY1;
        slopeDist = Math.sqrt(slopeX * slopeX + slopeY * slopeY);
        slopeX /= slopeDist;
        slopeY /= slopeDist;

        line1dist =
            Math.sqrt(distFromCenterX1 * distFromCenterX1 + distFromCenterY1 * distFromCenterY1);
        line2dist =
            Math.sqrt(distFromCenterX2 * distFromCenterX2 + distFromCenterY2 * distFromCenterY2);

        move = (distOnLine - last) / maxStep * wander;

        force1 = line1dist + distFromCenter;
        force2 = line2dist - distFromCenter;

        cap1 = Math.min(move, force1);
        cap2 = Math.min(move, force2);

        if (force1 < 0) distFromCenter -= force1;
        else if (force2 < 0) distFromCenter += force2;
        else distFromCenter += random(-cap1, cap2);

        if (finished) {
          RSTile t = l2.translateFromCenter(distFromCenter);
          curX = t.getX();
          curY = t.getY();
        } else {
          curX =
              (int)
                  Math.round(distOnLine * centerXdist + l1.getCenterX() + distFromCenter * slopeX);
          curY =
              (int)
                  Math.round(distOnLine * centerYdist + l1.getCenterY() + distFromCenter * slopeY);
        }

        xdist = curX - lastX;
        ydist = curY - lastY;
        dist = Math.sqrt(xdist * xdist + ydist * ydist);
        xdist /= dist;
        ydist /= dist;
        for (int j = 0; j < dist; j++)
          path.add(
              new RSTile((int) Math.round(xdist * j + lastX), (int) Math.round(ydist * j + lastY)));

        last = distOnLine;
        lastX = curX;
        lastY = curY;
      }
    }
    return cutUp(path);
  }
示例#9
0
 public PortNode(Line port) {
   super(port.getLineInfo(), true);
   this.port = port;
 }