Esempio n. 1
0
  /**
   * Draws an open star with a specified number of points.<br>
   * The center of this star is specified by centerX,centerY and its size is specified by radius
   * <br>
   * (As in the radius of the circle the star would fit inside). <br>
   * Precondition: points >= 2 <br>
   * Example: <br>
   * Expo.drawStar(g,300,200,100,8); <br>
   * Draws an open star with 8 points and a radius of 100 pixels whose center is located at the
   * coordinate (300,200).
   */
  public static void drawStar(Graphics g, int centerX, int centerY, int radius, int points) {
    int halfRadius = getHalfRadius(radius, points);
    int p = points;
    points *= 2;

    int xCoord[] = new int[points];
    int yCoord[] = new int[points];

    int currentRadius;

    for (int k = 0; k < points; k++) {
      if (k % 2 == 0) currentRadius = radius;
      else currentRadius = halfRadius;

      xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX;
      yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY;
    }

    int x = (p - 5) / 2 + 1;
    if (p >= 5 && p <= 51)
      switch (p % 4) {
        case 1:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          break;
        case 2:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3];
          break;
        case 3:
          yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2];
      }
    g.drawPolygon(xCoord, yCoord, points);
  }
Esempio n. 2
0
 public static void drawPolygon(
     Graphics g,
     int x1,
     int y1,
     int x2,
     int y2,
     int x3,
     int y3,
     int x4,
     int y4,
     int x5,
     int y5,
     int x6,
     int y6,
     int x7,
     int y7,
     int x8,
     int y8,
     int x9,
     int y9,
     int x10,
     int y10) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   myPoly.addPoint(x4, y4);
   myPoly.addPoint(x5, y5);
   myPoly.addPoint(x6, y6);
   myPoly.addPoint(x7, y7);
   myPoly.addPoint(x8, y8);
   myPoly.addPoint(x9, y9);
   myPoly.addPoint(x10, y10);
   g.drawPolygon(myPoly);
 }
Esempio n. 3
0
 /**
  * Draws an open irregular polygon using between 3 and 12 sets of provided coordinates. <br>
  * Examples: <br>
  * Expo.drawPolygon(g,100,300,200,100,300,300); // for a triangle
  * Expo.drawPolygon(g,525,300,600,250,650,250,725,300,725,350,650,400); // for a hexagon
  */
 public static void drawPolygon(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   g.drawPolygon(myPoly);
 }
Esempio n. 4
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int xCenter = getSize().width / 2;
    int yCenter = getSize().height / 2;
    int radius = (int) (Math.min(getSize().width, getSize().height) * 0.4);

    // Create a Polygon object
    Polygon polygon = new Polygon();

    // Add points to the polygon
    polygon.addPoint(xCenter + radius, yCenter);
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(2 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(2 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(3 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(3 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(4 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(4 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(5 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(5 * 2 * Math.PI / 6)));

    // Draw the polygon
    g.drawPolygon(polygon);
  }
  private void paintObstacle(Graphics g, Obstacle obstacle) {
    Polygon polygon = obstacle.getPolygon();
    boolean opaque = obstacle.getOpaque();

    if (opaque) {
      g.setColor(obstacle.getOpaqueBackgroundColor());
      g.fillPolygon(polygon);
      g.setColor(obstacle.getOpaqueForegroundColor());
      g.drawPolygon(polygon);
    } else {
      g.setColor(obstacle.getBackgroundColor());
      g.fillPolygon(polygon);
      g.setColor(obstacle.getForegroundColor());
      g.drawPolygon(polygon);
    }
  }
Esempio n. 6
0
  public void render(Graphics g) {
    double time = getTime() - startTime;

    int w = getWidth();
    int h = getHeight();

    int x = 200;
    int y = 100;

    g.setColor(Color.white);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.green);
    g.drawOval(x, y, 100, 100); // head
    g.fillOval(x, y, 100, 100); // head
    g.drawOval(x + 80, y, 100, 100); // big nose
    g.fillOval(x + 80, y, 100, 100); // big nose
    g.drawOval(x + 40, y - 35, 30, 60); // eyes
    g.fillOval(x + 40, y - 35, 30, 60); // eyes
    //      g.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
    /*
    g.setColor(Color.green);
    g.drawRect(x+30, y+85, 55, 37);
    g.fillRect(x+30, y+85, 55, 37);

    g.drawArc(x-100, y+48, 185, 150, 0, -130);
    g.fillArc(x-100, y+48, 185, 150, 25, -155);

    g.setColor(Color.white);
    g.drawArc(x-150, y+12, 180, 170, 0, -95);
    g.fillArc(x-150, y+12, 180, 170, 0, -95);  */

    //      drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
    g.setColor(Color.black);
    int bodyStartX = x + 31;
    int bodyStartY = y + 95;

    int[] bodyXs = {
      bodyStartX,
      bodyStartX - 10,
      bodyStartX - 20,
      bodyStartX - 30,
      bodyStartX - 40,
      bodyStartX - 45
    };
    int[] bodyYs = {
      bodyStartY,
      bodyStartY + 20,
      bodyStartY + 40,
      bodyStartY + 60,
      bodyStartY + 70,
      bodyStartY + 75
    };

    g.drawPolygon(bodyXs, bodyYs, 6);
  }
Esempio n. 7
0
  private void renderDirectionArrow(Graphics g) {
    if (widthArrow < 0) g.setColor(new Color(0, 0, 255, 150));
    else g.setColor(new Color(255, 0, 0, 150));

    g.fillPolygon(
        xPositionsArrow, yPositionsArrow, Math.min(xPositionsArrow.length, yPositionsArrow.length));
    g.setColor(new Color(0, 0, 0, 255));
    g.drawPolygon(
        xPositionsArrow, yPositionsArrow, Math.min(xPositionsArrow.length, yPositionsArrow.length));
  }
Esempio n. 8
0
  /**
   * This method is to be called from the <code>paint(Graphics g)</code> method of the drawing
   * panel/canvas. It uses the graphical context of the drawing panel/canvas to construct the
   * commentary box on the drawing panel/canvas.
   *
   * @param g Graphical context from the <code>paint(Graphics g)</code> method of the drawing
   *     panel/canvas.
   * @see Graphics
   */
  public void draw(Graphics g) {
    if (str.length() < 1) return;
    g.setColor(bg);
    g.fillPolygon(xPts, yPts, nPts);

    g.setColor(Color.black);
    g.drawPolygon(xPts, yPts, nPts);

    g.setColor(fg);
    g.setFont(font);
    g.drawString(str, topLeft.x + 4, topLeft.y + height - 10);
  }
Esempio n. 9
0
  /** Overrides <code>Graphics.drawPolygon</code>. */
  public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing polygon: "
                  + " nPoints: "
                  + nPoints
                  + " X's: "
                  + xPoints
                  + " Y's: "
                  + yPoints);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawPolygon(xPoints, yPoints, nPoints);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawPolygon(xPoints, yPoints, nPoints);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawPolygon(xPoints, yPoints, nPoints);
  }
Esempio n. 10
0
  /**
   * Draws an open regular polygon with a specified number of sides.<br>
   * The center of this polygon is specified by centerX,centerY and its size is specified by radius
   * <br>
   * (As in the radius of the circle the regular polygon would fit inside). <br>
   * Precondition: sides >= 3 <br>
   * Example: Expo.drawRegularPolygon(g,300,200,100,8); Draws an open regular octagon with a radius
   * of 100 pixels whose center is located at the coordinate (300,200).
   */
  public static void drawRegularPolygon(
      Graphics g, int centerX, int centerY, int radius, int sides) {
    int xCoord[] = new int[sides];
    int yCoord[] = new int[sides];

    double rotate;
    if (sides % 2 == 1) rotate = halfPI;
    else rotate = halfPI + Math.PI / sides;

    for (int k = 0; k < sides; k++) {
      xCoord[k] = (int) Math.round(Math.cos(twoPI * k / sides - rotate) * radius) + centerX;
      yCoord[k] = (int) Math.round(Math.sin(twoPI * k / sides - rotate) * radius) + centerY;
    }
    if (sides == 3) yCoord[1] = yCoord[2];
    g.drawPolygon(xCoord, yCoord, sides);
  }
Esempio n. 11
0
  @Override
  public void repaint(Graphics g) {
    if (tiles.size() >= 2) {
      g.setColor(new Color(255, 255, 255, 255));
      Tile[] t = new Tile[tiles.size()];
      tiles.toArray(t);
      Area a = new Area(t);
      for (int i = 0; i < a.getPolygon().npoints; i++) {
        Point p =
            new Point(
                tiles.get(i).matrix(ctx).bounds().xpoints[0],
                tiles.get(i).matrix(ctx).bounds().ypoints[0]);
        Point pp;
        if (i == a.getPolygon().npoints - 1)
          pp =
              new Point(
                  tiles.get(0).matrix(ctx).bounds().xpoints[0],
                  tiles.get(0).matrix(ctx).bounds().ypoints[0]);
        else
          pp =
              new Point(
                  tiles.get(i + 1).matrix(ctx).bounds().xpoints[0],
                  tiles.get(i + 1).matrix(ctx).bounds().ypoints[0]);
        g.drawLine(p.x, p.y, pp.x, pp.y);
      }
      g.drawPolygon(a.getPolygon());

      if (a.contains(ctx.players.local())) {
        g.setColor(new Color(0, 255, 0, 100));
      } else {
        g.setColor(new Color(255, 0, 0, 100));
      }
      g.fillPolygon(ctx.players.local().tile().matrix(ctx).bounds());
    } else {
      g.setColor(new Color(255, 0, 0, 100));
      g.fillPolygon(ctx.players.local().tile().matrix(ctx).bounds());
    }
    for (int i = 0; i < tiles.size(); i++) {
      if (i == gui.tileList.getSelectedIndex()) g.setColor(Color.yellow);
      else g.setColor(new Color(0, 0, 255, 150));
      g.fillPolygon(tiles.get(i).matrix(ctx).bounds());
    }
  }
  private static void paintTriangle(
      @NotNull Graphics g,
      @Nullable Color color,
      @Nullable Color borderColor,
      int x1,
      int x2,
      int y) {
    int size = 4;

    final int[] xPoints = new int[] {x1, x1, x2};
    final int[] yPoints = new int[] {y - size, y + size, y};

    if (color != null) {
      g.setColor(color);
      g.fillPolygon(xPoints, yPoints, xPoints.length);
    }
    if (borderColor != null) {
      g.setColor(borderColor);
      g.drawPolygon(xPoints, yPoints, xPoints.length);
    }
  }
Esempio n. 13
0
  // Draws nested shapes from the lab
  private void drawNestedShapes() {
    // Instantiates a Drawing panel
    DrawingPanel panel = new DrawingPanel(250, 250);
    panel.setTitle("Nested Shapes");

    // Get graphics from panel
    Graphics draw = panel.getGraphics();

    // Draw green square
    drawRect(draw, 25, 25, 200, 200, Color.green);

    // Draw cyan circle
    drawCircle(draw, 25, 25, 200, Color.magenta);

    // Draw cyan diamond
    draw.setColor(Color.cyan);
    draw.fillPolygon(new int[] {125, 224, 124, 25}, new int[] {25, 124, 224, 125}, 4);

    // Draw outline around diamond
    draw.setColor(Color.black);
    draw.drawPolygon(new int[] {125, 224, 124, 25}, new int[] {25, 124, 224, 125}, 4);
  }
  private void paintDevice(Graphics g, Device d) {
    // reads the robot's current position

    model.getRobot().readPosition(d.getRobotPosition());
    Polygon currentShape = d.getShape();
    // draws the shape
    Polygon globalShape = new Polygon();
    Point2D point = new Point2D.Double();
    for (int i = 0; i < currentShape.npoints; i++) {
      point.setLocation(currentShape.xpoints[i], currentShape.ypoints[i]);
      // calculates the coordinates of the point according to the local position
      d.getLocalPosition().rotateAroundAxis(point);
      // calculates the coordinates of the point according to the robot position
      d.getRobotPosition().rotateAroundAxis(point);
      // adds the point to the global shape
      globalShape.addPoint((int) Math.round(point.getX()), (int) Math.round(point.getY()));
    }
    g.setColor(d.getBackgroundColor());
    g.fillPolygon(globalShape);
    g.setColor(d.getForegroundColor());
    g.drawPolygon(globalShape);
  }
Esempio n. 15
0
 public static void drawPolygon(
     Graphics g,
     int x1,
     int y1,
     int x2,
     int y2,
     int x3,
     int y3,
     int x4,
     int y4,
     int x5,
     int y5,
     int x6,
     int y6) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   myPoly.addPoint(x4, y4);
   myPoly.addPoint(x5, y5);
   myPoly.addPoint(x6, y6);
   g.drawPolygon(myPoly);
 }
Esempio n. 16
0
  public void paint(Graphics g) {
    // do normal painting first
    super.paint(g);

    // draw polys
    ListIterator<Polygon> II = poly_draw.listIterator(0);
    ListIterator<Color> CC = poly_draw_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.drawPolygon(P);
    }

    // fill polys
    II = poly_fill.listIterator(0);
    CC = poly_fill_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.fillPolygon(P);
    }
  }
  public void flecha(Graphics papel, int x1, int y1, int x2, int y2) {
    double ang = 0.0, angSep = 0.0;
    double tx = 0, ty = 0;
    int dist = 0;
    Point punto1 = null, punto2 = null;

    punto2 = new Point(x1, y1);
    punto1 = new Point(x2, y2);

    dist = 15;

    ty = -(punto1.y - punto2.y) * 1.0;
    tx = (punto1.x - punto2.x) * 1.0;
    ang = Math.atan(ty / tx);

    if (tx < 0) ang += Math.PI;
    Point p1 = new Point(), p2 = new Point(), punto = punto2;
    angSep = 25.0;

    p1.x = (int) (punto.x + dist * Math.cos(ang - Math.toRadians(angSep)));
    p1.y = (int) (punto.y - dist * Math.sin(ang - Math.toRadians(angSep)));
    p2.x = (int) (punto.x + dist * Math.cos(ang + Math.toRadians(angSep)));
    p2.y = (int) (punto.y - dist * Math.sin(ang + Math.toRadians(angSep)));

    Graphics2D g2D = (Graphics2D) papel;
    papel.setColor(Color.black);
    g2D.setStroke(new BasicStroke(1.2f));
    papel.drawLine(punto1.x, punto1.y, punto.x, punto.y);

    int x[] = {p1.x, punto.x, p2.x};
    int y[] = {p1.y, punto.y, p2.y};
    Polygon myTri = new Polygon(x, y, 3);
    papel.setColor(Color.BLACK);
    papel.drawPolygon(myTri);
    papel.fillPolygon(myTri);
  }
Esempio n. 18
0
  public void paint(Graphics g) {
    // Draw Grid
    g.drawRect(0, 0, 780, 580);
    g.drawLine(400, 0, 400, 580);
    g.drawLine(0, 300, 780, 300);

    Random rndInt = new Random(1234);

    // Draw Random Squares

    for (int k = 1; k <= 1000; k++) {
      int x = rndInt.nextInt(385);
      int y = rndInt.nextInt(275);
      int red = rndInt.nextInt(256);
      int green = rndInt.nextInt(120);
      int blue = rndInt.nextInt(120);
      g.setColor(new Color(red, green, blue));
      g.fillRect(x, y, 15, 15);
    }
    // Draw Random Lines

    for (int k = 1; k <= 1000; k++) {
      int x1 = rndInt.nextInt(350);
      int y1 = rndInt.nextInt(300);
      int x2 = rndInt.nextInt(370);
      int y2 = rndInt.nextInt(300);
      g.drawLine(x1 + 400, y1, x2 + 400, y2);
      int red = rndInt.nextInt(100);
      int green = rndInt.nextInt(100);
      int blue = rndInt.nextInt(100);
      g.setColor(new Color(red, green, blue));
    }

    // Draw Random Circles
    for (int k = 1; k <= 1000; k++) {
      int x3 = rndInt.nextInt(385);
      int y3 = rndInt.nextInt(272);
      int red = rndInt.nextInt(240);
      int green = rndInt.nextInt(255);
      int blue = rndInt.nextInt(255);
      g.setColor(new Color(red, green, blue));
      g.drawOval(x3, y3 + 300, 11, 11);
    }
    // Draw 3-D Box
    {
      g.setColor(Color.blue);
      int x[] = {575, 675, 675, 575};
      int y[] = {425, 425, 525, 525};
      g.drawPolygon(x, y, 4);
      g.fillPolygon(x, y, 4);
    }
    {
      g.setColor(Color.yellow);
      int x1[] = {525, 575, 575, 525};
      int y1[] = {375, 425, 525, 475};
      g.drawPolygon(x1, y1, 4);
      g.fillPolygon(x1, y1, 4);
    }
    {
      g.setColor(Color.green);
      int x2[] = {525, 625, 625, 575};
      int y2[] = {375, 375, 425, 425};
      g.drawPolygon(x2, y2, 4);
      g.fillPolygon(x2, y2, 4);
    }
    {
      g.setColor(Color.red);
      int x3[] = {625, 625, 675};
      int y3[] = {375, 425, 425};
      g.drawPolygon(x3, y3, 3);
      g.fillPolygon(x3, y3, 3);
    }
  }
package gui;
Esempio n. 20
0
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      // Get the appropriate size for the figure
      int width = getWidth();
      int height = getHeight();

      switch (type) {
        case LINE: // Display two cross lines
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
        case RECTANGLE: // Display a rectangle
          g.setColor(Color.blue);
          if (filled)
            g.fillRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ROUND_RECTANGLE: // Display a round-cornered rectangle
          g.setColor(Color.red);
          if (filled)
            g.fillRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          else
            g.drawRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          break;
        case OVAL: // Display an Oval
          g.setColor(Color.black);
          if (filled)
            g.fillOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ARC: // Display an arc
          g.setColor(Color.blue);
          if (filled) {
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          } else {
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          }
          break;

        case POLYGON:
          g.setColor(Color.red);
          int radius = (int) (0.4 * Math.min(width, height));
          int xCenter = (int) (0.4 * width);
          int yCenter = (int) (0.4 * height);
          Polygon p = new Polygon();
          p.addPoint(xCenter + radius, yCenter);

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(3 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(3 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(4 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(4 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(5 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(5 * 2 * Math.PI / 6)));

          if (filled) {
            g.fillPolygon(p);
          } else {
            g.drawPolygon(p);
          }
          break;

        default:
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
      }
    }
Esempio n. 21
0
 public void draw(Graphics g) {
   updatePolygon();
   Color color = strokeColor != null ? strokeColor : ROIColor;
   boolean hasHandles = xSpline != null || type == POLYGON || type == POLYLINE || type == ANGLE;
   boolean isActiveOverlayRoi = !overlay && isActiveOverlayRoi();
   if (isActiveOverlayRoi && !hasHandles) {
     if (color == Color.cyan) color = Color.magenta;
     else color = Color.cyan;
   }
   boolean fill = false;
   mag = getMagnification();
   if (fillColor != null && !isLine() && state != CONSTRUCTING) {
     color = fillColor;
     fill = true;
   }
   g.setColor(color);
   Graphics2D g2d = (Graphics2D) g;
   if (stroke != null && !isActiveOverlayRoi) g2d.setStroke(getScaledStroke());
   if (xSpline != null) {
     if (type == POLYLINE || type == FREELINE) {
       drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       }
     } else drawSpline(g, xSpline, ySpline, splinePoints, true, fill, isActiveOverlayRoi);
   } else {
     if (type == POLYLINE || type == FREELINE || type == ANGLE || state == CONSTRUCTING) {
       g.drawPolyline(xp2, yp2, nPoints);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         g.drawPolyline(xp2, yp2, nPoints);
       }
     } else {
       if (fill) {
         if (isActiveOverlayRoi) {
           g.setColor(Color.cyan);
           g.drawPolygon(xp2, yp2, nPoints);
         } else g.fillPolygon(xp2, yp2, nPoints);
       } else g.drawPolygon(xp2, yp2, nPoints);
     }
     if (state == CONSTRUCTING && type != FREEROI && type != FREELINE) drawStartBox(g);
   }
   if (hasHandles && state != CONSTRUCTING && clipboard == null && !overlay) {
     int size2 = HANDLE_SIZE / 2;
     if (activeHandle > 0)
       drawHandle(g, xp2[activeHandle - 1] - size2, yp2[activeHandle - 1] - size2);
     if (activeHandle < nPoints - 1)
       drawHandle(g, xp2[activeHandle + 1] - size2, yp2[activeHandle + 1] - size2);
     handleColor = strokeColor != null ? strokeColor : ROIColor;
     drawHandle(g, xp2[0] - size2, yp2[0] - size2);
     handleColor = Color.white;
     for (int i = 1; i < nPoints; i++) drawHandle(g, xp2[i] - size2, yp2[i] - size2);
   }
   drawPreviousRoi(g);
   if (!(state == MOVING_HANDLE || state == CONSTRUCTING || state == NORMAL)) showStatus();
   if (updateFullWindow) {
     updateFullWindow = false;
     imp.draw();
   }
 }
Esempio n. 22
0
  public void paint(Graphics g) {
    // clears the area that the pannel is on
    gBuffer.setColor(Color.white);
    gBuffer.fillRect(0, 0, 65, 415);

    // pannel
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(5, 15, 60, 400);

    // color buttons
    gBuffer.setColor(Color.black); // first column
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.setColor(Color.red);
    gBuffer.fillRect(15, 40, 20, 20);
    gBuffer.setColor(Color.blue);
    gBuffer.fillRect(15, 60, 20, 20);
    gBuffer.setColor(Color.green);
    gBuffer.fillRect(15, 80, 20, 20);
    gBuffer.setColor(Color.yellow);
    gBuffer.fillRect(15, 100, 20, 20);
    gBuffer.setColor(Color.gray); // second column
    gBuffer.fillRect(35, 20, 20, 20);
    gBuffer.setColor(Color.magenta);
    gBuffer.fillRect(35, 40, 20, 20);
    gBuffer.setColor(Color.cyan);
    gBuffer.fillRect(35, 60, 20, 20);
    gBuffer.setColor(Color.orange);
    gBuffer.fillRect(35, 80, 20, 20);
    gBuffer.setColor(Color.pink);
    gBuffer.fillRect(35, 100, 20, 20);
    gBuffer.setColor(Color.black); // draw first column button outlines
    gBuffer.drawRect(15, 20, 20, 20);
    gBuffer.drawRect(15, 40, 20, 20);
    gBuffer.drawRect(15, 60, 20, 20);
    gBuffer.drawRect(15, 80, 20, 20);
    gBuffer.drawRect(15, 100, 20, 20);
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.drawRect(35, 20, 20, 20); // draw second column button outlines
    gBuffer.drawRect(35, 40, 20, 20);
    gBuffer.drawRect(35, 60, 20, 20);
    gBuffer.drawRect(35, 80, 20, 20);
    gBuffer.drawRect(35, 100, 20, 20);

    // pen button design
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(23, 125, 3, 20);
    penta = new Polygon();
    penta.addPoint(23, 145);
    penta.addPoint(26, 145);
    penta.addPoint(25, 148);
    gBuffer.drawPolygon(penta);

    // brush button design
    gBuffer.setColor(Color.gray);
    gBuffer.fillRect(45, 128, 3, 10);
    penta = new Polygon();
    penta.addPoint(45, 138);
    penta.addPoint(48, 138);
    penta.addPoint(51, 141);
    penta.addPoint(42, 141);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(42, 141, 9, 5);
    gBuffer.drawLine(45, 146, 45, 144);
    gBuffer.drawLine(48, 146, 48, 143);

    // roller button design
    gBuffer.setColor(Color.black); // handle
    gBuffer.fillRect(23, 155, 3, 10);
    gBuffer.drawRect(19, 165, 9, 4);
    gBuffer.setColor(Color.white); // roller front
    gBuffer.fillOval(27, 166, 4, 4);
    gBuffer.setColor(Color.black); // roller round side
    gBuffer.drawOval(27, 166, 3, 3);

    // spray paint button design
    gBuffer.setColor(Color.black); // top of can
    penta = new Polygon();
    penta.addPoint(43, 156);
    penta.addPoint(48, 160);
    penta.addPoint(43, 163);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.blue); // spray button
    gBuffer.fillRect(42, 155, 2, 3);
    for (int n = 0; n <= 20; n++) // paint spray
    {
      x = 39 + ((int) (3 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
      y = 157 + ((int) (3 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
      gBuffer.fillRect(x, y, 1, 1);
    }
    penta = new Polygon(); // can
    penta.addPoint(43, 163);
    penta.addPoint(48, 160);
    penta.addPoint(53, 172);
    penta.addPoint(48, 177);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawPolygon(penta);

    // rubber band drawing button design (20,185,30,205);
    gBuffer.setColor(Color.black);
    for (int a = 18, b = 200; a <= 35; a += 4, b += 2) {
      gBuffer.drawLine(18, 183, a, b);
    }

    // eraser button design
    gBuffer.setColor(Color.yellow); // top
    penta = new Polygon();
    penta.addPoint(45, 185);
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(40, 200);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.yellow); // side
    penta = new Polygon();
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(52, 189);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    penta = new Polygon(); // front
    penta.addPoint(40, 200);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(43, 204);
    gBuffer.drawPolygon(penta);

    // clear button design
    gBuffer.setColor(Color.black);
    gBuffer.setFont(new Font("Arial", Font.BOLD, 20));
    gBuffer.drawString("Clear", 10, 239);
    gBuffer.drawRect(10, 220, 50, 25);

    gBuffer.setColor(Color.cyan);
    switch (numSize) {
      case 1:
        gBuffer.drawRect(15, 120, 20, 30);
        break;
      case 2:
        gBuffer.drawRect(35, 120, 20, 30);
        break;
      case 3:
        gBuffer.drawRect(15, 150, 20, 30);
        break;
      case 4:
        gBuffer.drawRect(35, 150, 20, 30);
        break;
      case 5:
        gBuffer.drawRect(15, 180, 20, 30);
        break;
      case 6:
        gBuffer.drawRect(35, 180, 20, 30);
        break;
    }

    if ((numSize == 4) || (numSize == 6)) {
      // draw different size buttons for spray paint, eraser, and rubber band
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
      gBuffer.setColor(Color.cyan);
      switch (size) {
        case 1:
          gBuffer.drawRect(26, 271, 18, 18);
          break;
        case 2:
          gBuffer.drawRect(26, 291, 18, 18);
          break;
        case 3:
          gBuffer.drawRect(26, 311, 18, 18);
      }
      gBuffer.setColor(Color.black);
      gBuffer.drawRect(20, 265, 30, 70); // size pannel
      gBuffer.drawRect(25, 270, 20, 20); // small
      gBuffer.drawRect(25, 290, 20, 20); // medium
      gBuffer.drawRect(25, 310, 20, 20); // large

      if (numSize == 4) {
        for (int n = 0; n <= 20; n++) {
          x = 35 + ((int) (4 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 280 + ((int) (4 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 40; n++) {
          x = 34 + ((int) (6 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 300 + ((int) (6 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 70; n++) {
          x = 35 + ((int) (8 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 319 + ((int) (8 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 6;
            break;
          case 3:
            s = 8;
        }
      } else if (numSize == 6) {
        gBuffer.drawRect(33, 278, 4, 4);
        gBuffer.drawRect(32, 297, 7, 7);
        gBuffer.drawRect(30, 315, 10, 10);

        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 7;
            break;
          case 3:
            s = 10;
        }
      }
    } else {
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
    }

    // draw pannel and buttons
    g.drawImage(virtualMem, 0, 0, this);

    // changing what color it draws with
    switch (numColor) {
      case 1:
        gBuffer.setColor(Color.black);
        break;
      case 2:
        gBuffer.setColor(Color.red);
        break;
      case 3:
        gBuffer.setColor(Color.blue);
        break;
      case 4:
        gBuffer.setColor(Color.green);
        break;
      case 5:
        gBuffer.setColor(Color.yellow);
        break;
      case 6:
        gBuffer.setColor(Color.gray);
        break;
      case 7:
        gBuffer.setColor(Color.magenta);
        break;
      case 8:
        gBuffer.setColor(Color.cyan);
        break;
      case 9:
        gBuffer.setColor(Color.orange);
        break;
      case 10:
        gBuffer.setColor(Color.pink);
        break;
      case 11:
        gBuffer.setColor(Color.white);
        break;
      default:
        gBuffer.setColor(Color.black);
    }

    // changing how it draws
    switch (numDraw) {
      case 1: // clear drawing
        gBuffer.setColor(Color.white);
        gBuffer.fillRect(0, 0, appletWidth, appletHeight);
        g.drawImage(virtualMem, 0, 0, this);
        numDraw = 0;
        repaint();
        break;
      default:
        switch (numSize) {
          case 1: // draw with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 2: // draw with brush
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 4, 4);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 3: // draw with roller
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 10, 10);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 4: // draw with spray paint
            if (!first) {
              for (int n = 0; n <= 20; n++) {
                x = oldX + ((int) (s * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
                y = oldY + ((int) (s * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
                gBuffer.fillRect(x, y, 1, 1);
                g.drawImage(virtualMem, 0, 0, this);
              }
            } else first = false;

            break;
          case 5: // draw with rubber band style
            if (!first) {
              gBuffer.drawLine(startX, startY, endX, endY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 6: // eraser drawer
            if (!first) {
              gBuffer.fillRect(oldX, oldY, s, s);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          default: // default to drawing with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
        }
    }
  }
Esempio n. 23
0
  @Override
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    for (int l = 0; l < 6; l++) {
      for (int i = 0; i < 10; i++) {
        if (Grid.hus[i] != null) {
          if (dist(Grid.hus[i]._xpos, shapex[l], Grid.hus[i]._ypos, shapey[l]) <= 20
              && Grid.hus[i].myhouse == true) {
            itson = true;
          }
        }
      }
    }

    for (int l = 0; l < 6; l++) {
      for (int i = 0; i < 10; i++) {
        if (Grid.by[i] != null) {
          if (dist(Grid.by[i]._xpos, shapex[l], Grid.by[i]._ypos, shapey[l]) <= 20
              && Grid.by[i].myTown == true) {
            itsontown = true;
          }
        }
      }
    }

    for (int l = 0; l < 6; l++) {
      for (int i = 0; i < 10; i++) {
        if (Grid.hus[i] != null) {
          if (dist(Grid.hus[i]._xpos, shapex[l], Grid.hus[i]._ypos, shapey[l]) <= 80) {
            middlearray[l].occupied = true;
          }
        }
      }
    }

    for (int l = 0; l < 6; l++) {
      for (int i = 0; i < 10; i++) {
        if (Grid.enemyhus[i] != null) {
          if (dist(Grid.enemyhus[i]._xpos, shapex[l], Grid.enemyhus[i]._ypos, shapey[l]) <= 80) {
            middlearray[l].occupied = true;
          }
        }
      }
    }

    // dicechecker

    // draws the hexagon
    g.setColor(_color2);
    g2.setStroke(new BasicStroke(3));
    g.drawPolygon(shapex, shapey, 6);

    /*
    if (itsontown == true ) {
    	g.setColor(_color);// sets the color to green
    	g.fillPolygon(shapex, shapey, 6);// colors the hexagon
    } else if (itson == true) {
    		g.setColor( new Color(199, 21, 197)); // sets the color to black
    		g.fillPolygon(shapex, shapey, 6); // colors the hexagon
    	}*/

    if (colCode == 1) { // if the number from the server is 1
      g.setColor(wheat); // sets the color to yellow
    }
    if (colCode == 2) { // if the number from the server is 2
      g.setColor(stone); // sets the color to grey
    }
    if (colCode == 3) { // if the number from the server is 3
      g.setColor(brick); // sets the color to red
    }
    if (colCode == 4) { // if the number from the server is 4
      g.setColor(wood); // sets the color to green
    }
    if (colCode == 5) { // if the number from the server is 5
      g.setColor(sheep); // sets the color to light green
    }

    g.fillPolygon(shapex, shapey, 6); // colors the hexagon

    for (int b = 0; b < 6; b++) {
      middlearray[b].paint(g);

      for (int i = 0; i < 10; i++) {
        if (Grid.hus[i] != null) {
          Grid.hus[i].paint(g);
        }
      }
      for (int i = 0; i < 10; i++) {
        if (Grid.enemyhus[i] != null) {
          Grid.enemyhus[i].paint(g);
        }
      }
      for (int i = 0; i < 10; i++) {
        if (Grid.by[i] != null) {
          Grid.by[i].paint(g);
        }
      }
      for (int i = 0; i < 10; i++) {
        if (Grid.vej[i] != null) {
          Grid.vej[i].paint(g);
        }
      }
    }
    g.drawImage(image, _posy - 20, _posx - 20, null);
  }