コード例 #1
0
  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);
    }
  }
コード例 #2
0
 private void moveLine(Line l, DoublePoint latestPoint) {
   DoublePoint origEndPoint = l.getEnd();
   DoublePoint origStartPoint = l.getStart();
   // repaintRegion(origStartPoint, origEndPoint);
   repaint();
   int dx = (int) (latestPoint.getX() - origPoint.getX());
   int dy = (int) (latestPoint.getY() - origPoint.getY());
   origPoint = latestPoint;
   l.moveBy(dx, dy);
   DoublePoint newStartPoint = l.getStart();
   DoublePoint newEndPoint = l.getEnd();
   repaintRegion(newStartPoint, newEndPoint);
   repaint();
 }
コード例 #3
0
ファイル: Line.java プロジェクト: paleolimbot/java-geo
 public boolean equals(Object o) {
   // order does not matter, as with a vector
   if (o instanceof Line) {
     Line l = (Line) o;
     if (this.getStart().equals(l.getStart()) && this.getEnd().equals(l.getEnd())) {
       return true;
     } else if (this.getEnd().equals(l.getStart()) && this.getStart().equals(l.getEnd())) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
コード例 #4
0
ファイル: LineTest.java プロジェクト: Weltraumschaf/jebnf
 @Test
 public void create() {
   final Point start = Point.valueOf(5, 6);
   final Point end = Point.valueOf(50, 60);
   final Line sut = Line.valueOf(start, end);
   assertEquals(start, sut.getStart());
   assertEquals(end, sut.getEnd());
 }
コード例 #5
0
 /* Going to use Heron's Formula to for calculating the distance
  * first we calculate the distance of each of the sides,
  * and use that info to calcualate the height of the triangle, giving us back the
  * distance
  */
 private double calculateDistance(Line l, DoublePoint p) {
   double side1 = l.getStart().distance(l.getEnd());
   double side2 = l.getStart().distance(p);
   double side3 = l.getEnd().distance(p);
   double hS = (side1 + side2 + side3) / 2;
   double triangleArea = Math.sqrt(hS * (hS - side1) * (hS - side2) * (hS - side3));
   double distance = (2 * triangleArea) / side1;
   return distance;
 }
コード例 #6
0
ファイル: Line.java プロジェクト: paleolimbot/java-geo
  public static double interpolateY(Line line, double xValue) {
    // if point1.x() == point2.x(), is a vertical line, will produce an infinity value
    XY point1 = line.getStart();
    XY point2 = line.getEnd();
    double x1 = point1.x();
    double x2 = point2.x();
    double y1 = point1.y();
    double y2 = point2.y();

    return (y2 - y1) / (x2 - x1) * (xValue - x1) + y1;
  }
コード例 #7
0
ファイル: GameView.java プロジェクト: ghavelan/Four
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // If the game is paused we mask the game view
    if (hide) {
      setBackgroundColor(getResources().getColor(R.color.black));
    }
    // Otherwise if the game is pending
    else {

      setBackgroundResource(R.drawable.grid_background);
      // Fill the shapes
      if (mg != null && !mg.getShapes().isEmpty()) {

        for (Map.Entry<Rect, Integer> e : mg.getShapes().entrySet()) {
          fill.setColor(e.getValue());
          canvas.drawRect(e.getKey(), fill);
        }
      }
      // If you lose (there is at least one adjacent shape with the same color)
      if (adjacent != null && !adjacent.isEmpty()) {

        for (Rect rect : adjacent) {
          canvas.drawRect(rect, striped);
        }
      }
      // Stroke
      if (mg != null && !mg.getLines().isEmpty()) {

        for (Line line : mg.getLines()) {
          canvas.drawLine(
              line.getStart().x, line.getStart().y, line.getEnd().x, line.getEnd().y, stroke);
        }
      }
    }
  }
コード例 #8
0
 private void repaintLine(Line l) {
   repaintRegion(l.getStart(), l.getEnd());
 }
コード例 #9
0
 private void changeLine(Line l, DoublePoint latestPoint) {
   DoublePoint origEndPoint = l.getEnd();
   repaintRegion(l.getStart(), origEndPoint);
   l.setEndPoint(latestPoint);
   repaintRegion(origEndPoint, l.getEnd());
 }