public void paintComponent(Graphics g) {
    // System.out.println("Fin du tour !");
    int indx = 0;
    int indy = 0;
    int rayon = (int) 300 / Jeu.tailleGrille;

    int y = (int) 10 + (rayon / 2);
    int h = (int) Math.sqrt(3 / 2) * rayon;
    int x = (int) 10 + h;

    while (indy < Jeu.tailleGrille) {
      while (indx < Jeu.tailleGrille) {
        g.setColor(Color.decode(lcolor.get(Jeu.tailleGrille * indy + indx)));
        if (Jeu.modeJeu == "Carrée") {
          g.fillRect(
              (int) (10 + indx * 1.5 * rayon),
              (int) (10 + indy * 1.5 * rayon),
              (int) (1.5 * rayon - 1),
              (int) (1.5 * rayon - 1));
        } else {
          if (indy % 2 == 0) {
            x = (int) 25 + indx * 2 * h;
            int x2[] = {x, x + h, x + h, x, x - h, x - h};
            int y2[] = {
              y - rayon, y - rayon / 2, y + rayon / 2, y + rayon, y + rayon / 2, y - rayon / 2
            };
            g.fillPolygon(x2, y2, 6);
            g.setColor(Color.WHITE);
            g.drawPolygon(x2, y2, 6);
          } else {
            x = (int) 25 + indx * 2 * h + h;
            int x2[] = {x, x + h, x + h, x, x - h, x - h};
            int y2[] = {
              y - rayon, y - rayon / 2, y + rayon / 2, y + rayon, y + rayon / 2, y - rayon / 2
            };
            g.fillPolygon(x2, y2, 6);
            g.setColor(Color.WHITE);
            g.drawPolygon(x2, y2, 6);
          }
          g.setColor(Color.BLACK);
          // g.drawString(Integer.toString(Jeu.tailleGrille*indy+indx), 10+indx*35, 10+indy*35);

        }
        indx++;
      }
      indy++;
      y += 1.5 * rayon;
      indx = 0;
    }
  }
Example #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);
 }
Example #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);
 }
Example #4
0
    @Override
    public void paint(Graphics g) {
      Color b;
      Color f;
      if (entered) {
        b = UIManager.getColor("controlDkShadow");
        f = Color.BLACK;
      } else {
        b = UIManager.getColor("control");
        f = UIManager.getColor("controlDkShadow");
      }
      g.setColor(b);
      g.fillRect(0, 0, getWidth(), getHeight());
      int center = getWidth() / 2;
      int[] xs = {center, center - 3, center + 3};
      int[] ys;
      if (open) {
        ys = yup;

      } else {
        ys = ydown;
      }
      g.setColor(f);
      g.drawPolygon(xs, ys, 3);
      g.fillPolygon(xs, ys, 3);
    }
Example #5
0
 public void drawSelector(Graphics g, Color color, int x, int y) {
   g.setColor(color);
   Random rand = new Random();
   int[] polyX = new int[8];
   int[] polyY = new int[8];
   for (int i = 0; i < 4; i++) {
     polyX[0] = rand.nextInt(5) + x;
     polyY[0] = rand.nextInt(5) + y;
     polyX[1] = rand.nextInt(5) - 2 + x + 25;
     polyY[1] = rand.nextInt(5) + y;
     polyX[2] = rand.nextInt(5) - 5 + x + 50;
     polyY[2] = rand.nextInt(5) + y;
     polyX[3] = rand.nextInt(5) - 5 + x + 50;
     polyY[3] = rand.nextInt(5) - 2 + y + 25;
     polyX[4] = rand.nextInt(5) - 5 + x + 50;
     polyY[4] = rand.nextInt(5) - 5 + y + 50;
     polyX[5] = rand.nextInt(5) - 2 + x + 25;
     polyY[5] = rand.nextInt(5) - 5 + y + 50;
     polyX[6] = rand.nextInt(5) + x;
     polyY[6] = rand.nextInt(5) - 5 + y + 50;
     polyX[7] = rand.nextInt(5) + x;
     polyY[7] = rand.nextInt(5) - 2 + y + 25;
     g.drawPolygon(polyX, polyY, 8);
   }
 }
Example #6
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);
    }
  }
Example #8
0
 static void drawALUIcon(ComponentDrawContext context, int x, int y) {
   Graphics g = context.getGraphics();
   g.setColor(Color.BLACK);
   int xp[] = {x, x + 15, x + 15, x, x, x + 3, x};
   int yp[] = {y, y + 5, y + 10, y + 15, y + 10, y + 8, y + 6};
   g.drawPolygon(xp, yp, 7);
 }
Example #9
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);
  }
Example #10
0
 public void paint(Graphics g) {
   Polygon pt = at.transform(p);
   g.translate(xtranslate, ytranslate);
   g.drawPolygon(pt);
   for (int i = 0; i < pt.npoints; i++) g.drawString("p" + i, pt.xpoints[i], pt.ypoints[i]);
   Rectangle r = pt.getBounds();
   g.drawString("h=" + r.height + " w=" + r.width, r.height / 2, r.width / 2);
 }
Example #11
0
 public static void paintDescriptionMarker(Graphics g) {
   // int width = getWidth();
   // int height = getHeight();
   g.setColor(Color.RED);
   g.fillPolygon(POLYGON);
   g.setColor(Color.BLACK);
   g.drawPolygon(POLYGON);
 }
Example #12
0
 @Override
 public void paint(Graphics g) {
   g.clearRect(0, 0, siz.width, siz.height);
   g.setColor(Color.white);
   for (int i = 0; i < n; i++) {
     g.fillOval((int) p.get(i).x - 3, (int) p.get(i).y - 3, 7, 7);
   }
   g.drawString("<" + n + ">", 0, siz.height - 5);
   if (chok) {
     g.setColor(Color.yellow);
     g.drawPolygon(ch);
     if (ch2 != null) {
       g.setColor(Color.green);
       g.drawPolygon(ch2);
     }
   }
 }
Example #13
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);
  }
Example #14
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));
  }
Example #15
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Dimension size = c.getSize();
   Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
   g2.setColor(Color.GRAY);
   g2.drawPolygon(xPoints, yPoints, 3);
   if (c.isEnabled()) {
     g2.setColor(Color.BLACK);
     g2.fillPolygon(xPoints, yPoints, 3);
   }
   g2.dispose();
 }
Example #16
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);
  }
Example #17
0
 static void drawALU(Graphics g, Bounds bds) {
   int wid = bds.getWidth();
   int ht = bds.getHeight();
   int x0 = bds.getX();
   int x1 = x0 + wid;
   int y0 = bds.getY();
   int y1 = y0 + ht;
   int xp[] = {x0, x1, x1, x0, x0, x0 + 20, x0};
   int yp[] = {y0, y0 + 30, y1 - 30, y1, y1 - 40, y1 - 50, y1 - 60};
   GraphicsUtil.switchToWidth(g, 2);
   g.drawPolygon(xp, yp, 7);
 }
Example #18
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {

    if (type != NOICON) {
      g.setColor(Color.BLACK);

      if (type == DOWNARROW || type == UPDOWNARROW) {
        // draw arrow down
        Polygon p = new Polygon();
        p.addPoint(3, 1);
        p.addPoint(3, 12);
        p.addPoint(1, 12);
        p.addPoint(4, 15);
        p.addPoint(7, 12);
        p.addPoint(5, 12);
        p.addPoint(5, 1);
        g.drawPolygon(p);
        g.fillPolygon(p);
      }

      if (type == UPDOWNARROW) {
        // draw arrow up
        Polygon p = new Polygon();
        p.addPoint(12, 1);
        p.addPoint(9, 4);
        p.addPoint(11, 4);
        p.addPoint(11, 15);
        p.addPoint(13, 15);
        p.addPoint(13, 4);
        p.addPoint(15, 4);
        g.drawPolygon(p);
        g.fillPolygon(p);
      }

      if (type == CIRCLE) {
        g.drawRoundRect(6, 6, 5, 5, 4, 4);
      }
    }
  }
Example #19
0
  /**
   * Draw the polygon
   *
   * @param g the graphics object
   * @param container the drawing container
   */
  public void draw(Graphics g, IContainer container) {
    reset();
    Point pp = new Point();
    for (int i = 0; i < 4; i++) {
      container.worldToLocal(pp, paddle.getVolumePoint(i).x(), paddle.getVolumePoint(i).y());
      addPoint(pp.x, pp.y);
    }

    g.setColor(CedXYView.LIGHT);
    g.fillPolygon(this);
    g.setColor(Color.black);
    g.drawPolygon(this);
  }
Example #20
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);
  }
Example #21
0
 /**
  * Draws this tile to screen based on visibility and enemy status; visiblity 'n' == not visible,
  * 'e' == enemy and in visibility, 'm' == mine not in visibility, 'v' == in visibility
  *
  * @param g, visiblity
  */
 public void draw(Graphics g, char visiblity) {
   Polygon squareTile = _location.toPolygon(WIDTH);
   if (visiblity == 'n') {
     g.setColor(Color.blue.darker());
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   } else if (visiblity == 'e') {
     g.setColor(this.getOccupant().getColor());
     g.fillPolygon(squareTile);
     g.setColor(Color.red);
     g.drawPolygon(squareTile);
   } else if (visiblity == 'm') {
     g.setColor(Color.blue);
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   } else {
     g.setColor(this.getOccupant().getColor());
     g.fillPolygon(squareTile);
     g.setColor(Color.black);
     g.drawPolygon(squareTile);
   }
 }
Example #22
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);
  }
Example #23
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int halfHeight = this.getHeight() / 2;
    int halfWidth = this.getWidth() / 2;
    int radius;

    // Draw 0-oval
    g.setColor(new Color(0, 150, 0));
    radius = (halfHeight / 2);
    g.drawOval(halfWidth - radius, halfHeight - radius, 2 * radius, 2 * radius);
    g.drawString(
        "0",
        (int) (radius * Math.cos(Math.PI / 4) + halfWidth),
        (int) (halfHeight - radius * Math.sin(Math.PI / 4)));
    // Draw Infinity-oval
    radius = (halfHeight);
    g.drawOval(halfWidth - radius, halfHeight - radius, 2 * radius, 2 * radius);
    g.drawString(
        "Infty",
        (int) (radius * Math.cos(Math.PI / 4) + halfWidth),
        (int) (halfHeight - radius * Math.sin(Math.PI / 4)));

    // Draw StepNum, if applicable
    if (currentForm == Form.step) {
      g.drawString("Step: " + currentStep, this.getWidth() - 75, 20);
    }
    // Draw Polygons
    List<Polygon> polygons = generatePolygons();
    if (polygons == null) {
      return;
    }
    int num = polygons.size();
    int i = 0;
    for (Polygon p : polygons) {
      g.setColor(
          new Color(
              Math.min(510 - (i * 255 * 2) / num, 255), Math.min((i * 255 * 2) / num, 255), 0));
      i++;
      g.drawPolygon(p);

      int circDiam = 5;
      for (int j = 0; j < p.npoints; j++) {
        g.fillOval(p.xpoints[j] - circDiam / 2, p.ypoints[j] - circDiam / 2, circDiam, circDiam);
      }
    }
  }
Example #24
0
  @Override
  public void draw(Graphics g) {
    g.setColor(getColorSettings().getColor());
    List<Point> curvePoints = getCurvePoints();

    if (getSolidSettings().isSolid()) {
      if (getSolidSettings().isFilled()) {
        g.fillPolygon(
            PointUtil.getXs(curvePoints), PointUtil.getYs(curvePoints), curvePoints.size());
      } else {
        g.drawPolygon(
            PointUtil.getXs(curvePoints), PointUtil.getYs(curvePoints), curvePoints.size());
      }
    } else {
      g.drawPolyline(
          PointUtil.getXs(curvePoints), PointUtil.getYs(curvePoints), curvePoints.size());
    }
  }
Example #25
0
  /**
   * Draws a polygon using the currently set coordinates to the canvas.
   *
   * @param fill determines whether or not to fill the drawn polygon, or just draw an outline.
   * @return the constructed Polygon object.
   * @throws GeoException
   * @see java.awt.Polygon
   */
  public Polygon drawPolygon(final Graphics canvas, final boolean fill) throws GeoException {

    if (coords.size() == 0) {
      throw (new GeoException("Empty coordinate data."));
    } else {
      Polygon p = new Polygon();
      for (int i = 0; i < coords.size(); i++) {
        int[] points = coords.get(i);
        p.addPoint(points[0], points[1]);
      }
      if (fill) {
        canvas.fillPolygon(p);
      } else {
        canvas.drawPolygon(p);
      }
      return p;
    }
  }
  // paintX - paints an x in a rectangle with ULC (ULCx, ULCy) and width and height w and h
  private void paintX(Graphics g, int ULCx, int ULCy, int w, int h) {
    int[] xs = new int[16];
    int[] ys = new int[16];

    double pt = 0.05 * Math.sqrt(2);
    xs[0] = (int) (ULCx + pt * w);
    ys[0] = (int) (ULCy + pt * h);
    xs[1] = xs[0];
    ys[1] = (int) (ULCy + 2 * pt * h);
    xs[2] = (int) (ULCx + (0.5 - pt) * w);
    ys[2] = (int) (ULCy + 0.5 * h);
    xs[3] = xs[0];
    ys[3] = (int) (ULCy + (1 - 2 * pt) * h);
    xs[4] = xs[0];
    ys[4] = (int) (ULCy + (1 - pt) * h);
    xs[5] = (int) (ULCx + (2 * pt) * w);
    ys[5] = ys[4];
    xs[6] = (int) (ULCx + 0.5 * w);
    ys[6] = (int) (ULCy + (0.5 + pt) * h);
    xs[7] = (int) (ULCx + (1 - 2 * pt) * w);
    ys[7] = ys[4];
    xs[8] = (int) (ULCx + (1 - pt) * w);
    ys[8] = ys[4];
    xs[9] = xs[8];
    ys[9] = ys[3];
    xs[10] = (int) (ULCx + (0.5 + pt) * w);
    ys[10] = ys[2];
    xs[11] = xs[8];
    ys[11] = ys[1];
    xs[12] = xs[8];
    ys[12] = ys[0];
    xs[13] = xs[7];
    ys[13] = ys[0];
    xs[14] = xs[6];
    ys[14] = (int) (ULCy + (0.5 - pt) * h);
    xs[15] = xs[5];
    ys[15] = ys[0];

    g.setColor(Color.RED);
    g.fillPolygon(xs, ys, 16);
    g.setColor(Color.BLACK);
    g.drawPolygon(xs, ys, 16);
  }
Example #27
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);
    }
  }
  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);
  }
Example #30
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);
  }