Esempio n. 1
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
Esempio n. 2
0
 public void paint(Graphics canvas) {
   this.setBackground(Color.WHITE);
   canvas.setColor(Color.GREEN);
   canvas.fillPolygon(xBranches, yBranches, xBranches.length);
   canvas.setColor(Color.GRAY);
   canvas.fillPolygon(xTrunk, yTrunk, xTrunk.length);
 }
Esempio n. 3
0
  public void paint(Graphics g) {
    super.paint(g);

    Dimension size = getSize();
    double w = size.getWidth() - 50;
    double h = size.getHeight() + 20;

    try {
      readFile();
    } catch (IOException e) {
      System.err.println("IO issue");
    }

    barWidth = ((int) (w / numBars)) - 20;
    pos = 5;

    int xPos[] = {pos, pos, pos, pos};
    int yPos[] = {pos, pos, pos, pos};

    maxVal = maxValue(values);
    double barH, ratio;

    for (int i = 0; i < numBars - 1; i++) {
      Color col[] = new Color[numBars];
      for (int j = 0; j < numBars - 1; j++) {
        col[j] = new Color((int) (Math.random() * 0x1000000));
      }

      ratio = (double) values[i] / (double) maxVal;
      barH = ((h) * ratio) - 10;

      xPos[0] = pos;
      xPos[2] = pos + barWidth;
      xPos[1] = xPos[0];
      xPos[3] = xPos[2];
      yPos[0] = (int) h;
      yPos[1] = (int) barH;
      yPos[2] = yPos[1];
      yPos[3] = yPos[0];

      System.out.println(
          "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio
              + " pos:" + pos);

      int stringPtsY[] = {
        ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180
      };
      int stringPtsX[] = {600, 600, 580, 580};

      g.setColor(col[i]);
      g.fillPolygon(xPos, yPos, xPos.length);

      g.fillPolygon(stringPtsX, stringPtsY, 4);
      g.setColor(Color.black);
      g.drawString(labels[i], 610, ((i + 1) * 20) + 195);
      pos = pos + barWidth + 10;
    }
  }
Esempio n. 4
0
  /**
   * Draws a solid "filled in" 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.fillStar(g,300,200,100,8); <br>
   * Draws a solid star with 8 points and a radius of 100 pixels whose center is located at the
   * coordinate (300,200).
   */
  public static void fillStar(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.fillPolygon(xCoord, yCoord, points);
  }
Esempio n. 5
0
  private void draw_horizon(int rad, Point center, int[] angles) {
    // Draw an arc
    int arc_angle =
        ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0]));

    Polygon remainder = new Polygon();

    offgraphics_.setColor(GREEN);
    offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle);

    if (pitch_ != 0) {
      if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90))
        offgraphics_.setColor(BLUE);

      int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360;

      // System.out.println (points[0] + " " + points[1]);

      // System.out.println (accepted_point);

      remainder.addPoint(
          center.x + polar_to_rect_x(rad, cover_angle),
          center.y - polar_to_rect_y(rad, cover_angle));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0]));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1]));
      offgraphics_.fillPolygon(remainder);
      // offgraphics_.setColor (getBackground ());
      // offgraphics_.drawPolygon (remainder);
    }
  }
Esempio n. 6
0
  void draw(Graphics g) {
    setBbox(point1, point2, hs);
    adjustBbox(gate[0], gate[1]);

    double v1 = volts[anode];
    double v2 = volts[cnode];

    draw2Leads(g);

    // draw arrow thingy
    setPowerColor(g, true);
    setVoltageColor(g, v1);
    g.fillPolygon(poly);

    // draw thing arrow is pointing to
    setVoltageColor(g, v2);
    drawThickLine(g, cathode[0], cathode[1]);

    drawThickLine(g, lead2, gate[0]);
    drawThickLine(g, gate[0], gate[1]);

    curcount_a = updateDotCount(ia, curcount_a);
    curcount_c = updateDotCount(ic, curcount_c);
    curcount_g = updateDotCount(ig, curcount_g);
    if (sim.dragElm != this) {
      drawDots(g, point1, lead2, curcount_a);
      drawDots(g, point2, lead2, curcount_c);
      drawDots(g, gate[1], gate[0], curcount_g);
      drawDots(g, gate[0], lead2, curcount_g + distance(gate[1], gate[0]));
    }
    drawPosts(g);
  }
Esempio n. 7
0
 public static void drawArrow(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) {
   // Draw line using user defined drawline() which can specify line width
   drawLine(g, x1, y1, x2, y2, lineWidth);
   // Calculate x-y values for arrow head
   calcValues(x1, y1, x2, y2);
   g.fillPolygon(xValues, yValues, 3);
 }
Esempio n. 8
0
  /**
   * Draw the LineSelection at its current location. It is the responsibility of the
   * applet/application to draw the LineSelection at the appropriate times, e.g., inside the
   * component's update() and/or paint() method. This gives maximum flexibility for double
   * buffering, etc.
   *
   * @param g The Graphics context to use for drawing.
   */
  public void draw(Graphics g) {

    if (!isVisible()) {
      return;
    }

    Color saveColor = g.getColor();
    g.setColor(color);
    if (thickness > 1) {
      double ratio = ((double) thickness) / ((double) length());
      double txdb = ratio * ((double) height) / 2.0;
      int tx = txdb > 0 ? ((int) Math.ceil(txdb)) : ((int) Math.floor(txdb));
      double tydb = -ratio * ((double) width) / 2.0;
      int ty = tydb > 0 ? ((int) Math.ceil(tydb)) : ((int) Math.floor(tydb));
      Point[] poly = new Point[4];
      for (int i = 0; i < 4; i++) poly[i] = new Point(x, y);
      poly[0].translate(tx, ty);
      poly[1].translate(-tx, -ty);
      poly[2].translate(width, height);
      poly[2].translate(-tx, -ty);
      poly[3].translate(width, height);
      poly[3].translate(tx, ty);
      Polygon polygon = new Polygon();
      for (int i = 0; i < 4; i++) polygon.addPoint(poly[i].x, poly[i].y);
      g.fillPolygon(polygon);
    } else g.drawLine(x, y, x + width, y + height);
    g.setColor(saveColor);
  } // end draw
Esempio n. 9
0
 /**
  * Draws a solid "filled-in" irregular polygon using between 3 and 12 sets of provided
  * coordinates. <br>
  * Examples: <br>
  * Expo.fillPolygon(g,100,300,200,100,300,300); // for a triangle
  * Expo.fillPolygon(g,525,300,600,250,650,250,725,300,725,350,650,400); // for a hexagon
  */
 public static void fillPolygon(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.fillPolygon(myPoly);
 }
  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. 11
0
 public static void fillPolygon(
     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.fillPolygon(myPoly);
 }
Esempio n. 12
0
  /* ウィンドウの描画 */
  public void draw(Graphics g) {
    super.draw(g); // ウィンドウ描画

    if (active) {
      /* 選択肢リストの描画 */
      for (int y = 0; y < select_list.length; y++) {
        int my = posY + AROUND_Y + (MessageString.FONT_HEIGHT + INTERVAL_Y) * y;
        for (int x = 0; x < select_list[y].length; x++) {
          int mx = posX + AROUND_X + (row_width + INTERVAL_X) * x;
          message.drawMessage(g, mx, my, select_list[y][x]);
        }
      }

      /* カーソルの描画 */
      int cx =
          posX + AROUND_X + (row_width + INTERVAL_X) * select_point.x - MessageString.FONT_WIDTH;
      int cy =
          posY
              + AROUND_Y
              + (MessageString.FONT_HEIGHT + INTERVAL_Y) * select_point.y
              + MessageString.FONT_WIDTH / 2;
      int[] xPoints = {cx, cx + MessageString.FONT_WIDTH / 2, cx};
      int[] yPoints = {cy, cy + MessageString.FONT_HEIGHT / 4, cy + MessageString.FONT_HEIGHT / 2};
      g.setColor(Color.WHITE);
      g.fillPolygon(xPoints, yPoints, 3);
    }
  }
Esempio n. 13
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (drawOverlay) {
      g = g.create();
      AntialiasingManager.activateAntialiasing(g);

      try {
        // Paint a roll over fade out.
        FadeTracker fadeTracker = FadeTracker.getInstance();

        float visibility = 0.0f;
        if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
          visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
          visibility /= 4;
        } else visibility = 0.5f;

        // Draw black overlay
        g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility));
        g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10);

        // Draw arrow
        g.setColor(Color.WHITE);

        int[] arrowX = new int[] {width - 17, width - 7, width - 12};
        int[] arrowY = new int[] {height - 12, height - 12, height - 7};
        g.fillPolygon(arrowX, arrowY, arrowX.length);
      } finally {
        g.dispose();
      }
    }
  }
Esempio n. 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));
  }
Esempio n. 15
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());
    }
  }
Esempio n. 16
0
    /**
     * Paints the icon.
     *
     * @param g context.
     */
    public void paint(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;

      g.setColor(Color.WHITE);

      Object aaval = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (collapsed) {
        int arrowX = 1;
        int arrowY = 0;
        g.fillPolygon(
            new int[] {arrowX, arrowX + 7, arrowX}, new int[] {arrowY, arrowY + 4, arrowY + 9}, 3);
      } else {
        int arrowX = 0;
        int arrowY = 1;
        g.fillPolygon(
            new int[] {arrowX, arrowX + 4, arrowX + 9}, new int[] {arrowY, arrowY + 7, arrowY}, 3);
      }
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaval);
    }
Esempio n. 17
0
    /**
     * Draws this polygon on the screen. If any of the points are not visible (ie. behind the
     * camera) then do not attempt to draw this polygon.
     */
    void draw(Graphics g) {
      if (n <= 1) return;
      g.setColor(getColor());

      for (int i = 0; i < n; i++) {
        if (!visibles[points[i] / 3]) return;
        xs[i] = (int) ps_[points[i] + 1];
        ys[i] = (int) ps_[points[i] + 2];
      }

      g.fillPolygon(xs, ys, xs.length);
    }
Esempio n. 18
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. 19
0
  public void drawVertArrow(Graphics g, int x1, int y1, int x2, int y2) {
    g.drawLine(x1, y1, x2, y2);

    int[] axPoints = new int[3];
    int[] ayPoints = new int[3];

    axPoints[0] = x2;
    ayPoints[0] = y2;
    axPoints[1] = x2 - 1;
    ayPoints[1] = y2 - 2;
    axPoints[2] = x2 + 2;
    ayPoints[2] = y2 - 2;

    g.fillPolygon(axPoints, ayPoints, 3);
  }
Esempio n. 20
0
  /** Overrides <code>Graphics.fillPolygon</code>. */
  public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
    DebugGraphicsInfo info = info();

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

        debugGraphics.fillPolygon(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.fillPolygon(xPoints, yPoints, nPoints);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillPolygon(xPoints, yPoints, nPoints);
  }
 void flechaAceleracion(Graphics g) {
   int i = orgXX + 8 * cAncho;
   byte byte0 = -1;
   int j = 2 * cAlto * byte0;
   Polygon polygon = new Polygon();
   polygon.addPoint(i + 2, y1);
   polygon.addPoint(i + 2, y1 - j);
   polygon.addPoint(i + 4, y1 - j);
   polygon.addPoint(i, y1 - j - 4 * byte0);
   polygon.addPoint(i - 4, y1 - j);
   polygon.addPoint(i - 2, y1 - j);
   polygon.addPoint(i - 2, y1);
   g.setColor(Color.red);
   g.fillPolygon(polygon);
 }
 void flechaVelocidad(Graphics g) {
   int i = orgXX + 11 * cAncho;
   byte byte0 = ((byte) (v <= (double) 0 ? -1 : 1));
   int j = (int) ((v * (double) 4 * (double) cAlto) / (double) 100);
   Polygon polygon = new Polygon();
   polygon.addPoint(i + 2, y1);
   polygon.addPoint(i + 2, y1 - j);
   polygon.addPoint(i + 4, y1 - j);
   polygon.addPoint(i, y1 - j - 4 * byte0);
   polygon.addPoint(i - 4, y1 - j);
   polygon.addPoint(i - 2, y1 - j);
   polygon.addPoint(i - 2, y1);
   g.setColor(Color.blue);
   g.fillPolygon(polygon);
 }
Esempio n. 23
0
  /*public void draw(Graphics g)
  {
  	if(alive||ghostCount%2==0)
  	{
  		super.draw(g);
  		g.setColor(color);
  		drawPolygon(g,location.xInt(),location.yInt(),4,angle.getValue());
  		g.setColor(Color.white);
  		g.drawLine(location.xInt(),location.yInt(),(int)(location.x()+10*Math.cos(sightAngle.getValue())),(int)(location.y()+10*Math.sin(sightAngle.getValue())));//add 90
  	}




  }*/
  private static void drawPolygon(Graphics g, int centerX, int centerY, int sides, double theta) {
    int[] x = new int[sides];
    int[] y = new int[sides];
    int index = 0;
    theta += Math.PI / 4;

    while (index < sides) {

      // System.out.println("theta is "+theta+" with sides: "+sides);
      x[index] = (int) (centerX + 10 * Math.cos(theta));
      y[index] = (int) (centerY + 10 * Math.sin(theta));
      index++;
      theta += 2 * Math.PI / sides;
    }
    g.fillPolygon(x, y, sides);
  }
Esempio n. 24
0
 public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) {
   if (lineWidth == 1) g.drawLine(x1, y1, x2, y2);
   else {
     double angle;
     double halfWidth = ((double) lineWidth) / 2.0;
     double deltaX = (double) (x2 - x1);
     double deltaY = (double) (y2 - y1);
     if (x1 == x2) angle = Math.PI;
     else angle = Math.atan(deltaY / deltaX) + Math.PI / 2;
     int xOffset = (int) (halfWidth * Math.cos(angle));
     int yOffset = (int) (halfWidth * Math.sin(angle));
     int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset};
     int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1};
     g.fillPolygon(xCorners, yCorners, 4);
   }
 }
Esempio n. 25
0
  /**
   * Draws a solid "filled in" 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.fillRegularPolygon(g,300,200,100,8); Draws a solid "filled-in" regular octagon
   * with a radius of 100 pixels whose center is located at the coordinate (300,200).
   */
  public static void fillRegularPolygon(
      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.fillPolygon(xCoord, yCoord, sides);
  }
 public void drawbranch(Graphics g, float width, int x0, int y0, int x1, int y1) {
   if (width < 1.5f) {
     g.drawLine(x0, y0, x1, y1);
     return;
   }
   int h = (int) (width);
   int x[] = new int[4];
   int y[] = new int[4];
   if (Math.abs(x1 - x0) < Math.abs(y1 - y0)) {
     x[0] = x0 - h;
     x[1] = x0 + h;
     x[2] = x1 + h;
     x[3] = x1 - h;
     if (y0 < y1) {
       y[0] = y0 - h;
       y[1] = y0 - h;
       y[2] = y1 + h;
       y[3] = y1 + h;
     } else {
       y[0] = y0 + h;
       y[1] = y0 + h;
       y[2] = y1 - h;
       y[3] = y1 - h;
     }
   } else {
     y[0] = y0 - h;
     y[1] = y0 + h;
     y[2] = y1 + h;
     y[3] = y1 - h;
     if (x0 < x1) {
       x[0] = x0 - h;
       x[1] = x0 - h;
       x[2] = x1 + h;
       x[3] = x1 + h;
     } else {
       x[0] = x0 + h;
       x[1] = x0 + h;
       x[2] = x1 - h;
       x[3] = x1 - h;
     }
   }
   g.fillPolygon(x, y, 4);
 }
Esempio n. 27
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      int w = getIconWidth();
      int h = w;
      Polygon p = new Polygon();
      switch (direction) {
        case EAST:
          p.addPoint(x + 2, y);
          p.addPoint(x + w - 2, y + h / 2);
          p.addPoint(x + 2, y + h - 1);
          break;

        case SOUTH:
          p.addPoint(x, y + 2);
          p.addPoint(x + w / 2, y + h - 2);
          p.addPoint(x + w - 1, y + 2);
          break;
      }
      g.fillPolygon(p);
    }
  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. 29
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);
  }