Пример #1
0
  public void drawEventBasedGateway(int x, int y, int width, int height) {
    // rhombus
    drawGateway(x, y, width, height);
    double scale = .6;

    drawCatchingEvent(
        (int) (x + width * (1 - scale) / 2),
        (int) (y + height * (1 - scale) / 2),
        (int) (width * scale),
        (int) (height * scale),
        false,
        null);

    double r = width / 6.;

    // create pentagon (coords with respect to center)
    int topX = (int) (.95 * r); // top right corner
    int topY = (int) (-.31 * r);
    int bottomX = (int) (.59 * r); // bottom right corner
    int bottomY = (int) (.81 * r);

    int[] xPoints = new int[] {0, topX, bottomX, -bottomX, -topX};
    int[] yPoints = new int[] {-(int) r, topY, bottomY, bottomY, topY};
    Polygon pentagon = new Polygon(xPoints, yPoints, 5);
    pentagon.translate(x + width / 2, y + width / 2);

    // draw
    g.drawPolygon(pentagon);
  }
Пример #2
0
  public Polygon scalePolygon(Polygon polygon) {
    int xs[] = new int[polygon.npoints];
    int ys[] = new int[polygon.npoints];
    math.geom2d.Point2D p;
    math.geom2d.Point2D p1;
    int sumX = 0;
    int sumY = 0;

    for (int i = 0; i < polygon.npoints; i++) {
      p = new math.geom2d.Point2D(polygon.xpoints[i], polygon.ypoints[i]);
      p1 = p.scale(0.5);
      sumX += p1.getX();
      sumY += p1.getY();

      xs[i] = (int) p1.getX();
      ys[i] = (int) p1.getY();
      p.clone();
    }

    Polygon poly = new Polygon(xs, ys, polygon.npoints);
    poly.translate(sumX / polygon.npoints, sumY / polygon.npoints);

    Polygon scalePolygon = new Polygon();

    for (int i = 0; i < poly.npoints; i++) {
      p = new math.geom2d.Point2D(poly.xpoints[i], poly.ypoints[i]);
      if (i + 1 < poly.npoints) {
        if (p.distance(poly.xpoints[i + 1], poly.ypoints[i + 1]) > (0.1 * world.getMapWidth())) {
          scalePolygon.addPoint(poly.xpoints[i], poly.ypoints[i]);
        } else {
          continue;
        }
      } else if (i + 1 == poly.npoints) {
        if (p.distance(poly.xpoints[0], poly.ypoints[0]) > (0.1 * world.getMapWidth())) {
          scalePolygon.addPoint(poly.xpoints[i], poly.ypoints[i]);
        } else {
          continue;
        }
      }
    }

    return scalePolygon;
  }
Пример #3
0
 public void moveDown() {
   posY += 3;
   bodyShape.translate(0, 3);
   headShape.translate(0, 3);
   updateShapes();
 }
Пример #4
0
 public void moveUp() {
   posY -= 3;
   bodyShape.translate(0, -3);
   headShape.translate(0, -3);
   updateShapes();
 }
Пример #5
0
 public void moveRight() {
   posX += 3;
   bodyShape.translate(3, 0);
   headShape.translate(3, 0);
   updateShapes();
 }
Пример #6
0
 // Move methods
 public void moveLeft() {
   posX -= 3;
   bodyShape.translate(-3, 0);
   headShape.translate(-3, 0);
   updateShapes();
 }
 // PMElement interface methods
 public void translate(int x, int y) {
   areaShape.translate(x, y);
 }