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) { 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); g.drawPolygon(myPoly); }
private void drawArrow(Graphics2D g2d, double sx, double sy, double px, double py, int pass) { if (pass == 0) { g2d.setStroke(new BasicStroke(4.0f)); g2d.setPaint(preSynapticSiteColor.brighter()); g2d.draw(new Line2D.Double(sx, sy, px, py)); return; } double dx = px - sx; double dy = py - sy; Polygon tip = new Polygon(); tip.addPoint(0, 0); tip.addPoint(-10, -20); tip.addPoint(10, -20); AffineTransform transform = new AffineTransform(); transform.concatenate(AffineTransform.getTranslateInstance(px, py)); transform.concatenate(AffineTransform.getScaleInstance(0.5, 0.5)); transform.concatenate(AffineTransform.getRotateInstance(Math.atan2(dy, dx) - Math.PI * 0.5)); Shape shape = new GeneralPath(tip).createTransformedShape(transform); g2d.setPaint(preSynapticSiteColor.darker().darker()); g2d.draw(shape); g2d.setPaint(preSynapticSiteColor.brighter().brighter()); g2d.fill(shape); }
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) { 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); g.fillPolygon(myPoly); }
// From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135 void drawArrow( Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke, BasicStroke drawStroke) { double aDir = Math.atan2(xCenter - x, yCenter - y); // Line can be dashed. g2d.setStroke(drawStroke); g2d.drawLine(x, y, xCenter, yCenter); // make the arrow head solid even if dash pattern has been specified g2d.setStroke(lineStroke); Polygon tmpPoly = new Polygon(); int i1 = 12 + (int) (stroke * 2); // make the arrow head the same size regardless of the length length int i2 = 6 + (int) stroke; tmpPoly.addPoint(x, y); tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); // Remove this line to leave arrow head unpainted: g2d.fillPolygon(tmpPoly); }
public void drawConditionalSequenceFlowIndicator(Line2D.Double line) { int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
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); } }
private Polygon getPolygon(ShapeValue s, int w, int h) { Geometry g = s.getGeometry(); Polygon ret = new Polygon(); HashSet<String> points = new HashSet<String>(); int sx = 0, sy = 0; for (Coordinate c : g.getBoundary().getCoordinates()) { int x = (int) ((double) w * (c.x + 180.0) / 360.0); int y = h - (int) ((double) h * (c.y + 90.0) / 180.0); if (!points.contains(x + "|" + y)) { if (ret.npoints == 0) { sx = x; sy = y; } ret.addPoint(x, y); points.add(x + "|" + y); } } /* * close polygon */ if (ret.npoints > 0) { ret.addPoint(sx, sy); } return ret; }
/** * 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); }
/** 绘制网关 */ protected static void drawGateway(int x, int y, int width, int height, Graphics2D graphics) { Polygon rhombus = new Polygon(); rhombus.addPoint(x, y + (height / 2)); rhombus.addPoint(x + (width / 2), y + height); rhombus.addPoint(x + width, y + (height / 2)); rhombus.addPoint(x + (width / 2), y); graphics.draw(rhombus); }
public void drawGateway(int x, int y, int width, int height) { Polygon rhombus = new Polygon(); rhombus.addPoint(x, y + (height / 2)); rhombus.addPoint(x + (width / 2), y + height); rhombus.addPoint(x + width, y + (height / 2)); rhombus.addPoint(x + (width / 2), y); g.draw(rhombus); }
public static void drawPolygon( Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { Polygon myPoly = new Polygon(); myPoly.addPoint(x1, y1); myPoly.addPoint(x2, y2); myPoly.addPoint(x3, y3); myPoly.addPoint(x4, y4); g.drawPolygon(myPoly); }
public void paintIcon(Component c, Graphics g, int x, int y) { int w = getIconWidth(), h = getIconHeight(); g.setColor(Color.black); Polygon p = new Polygon(); p.addPoint(x + 1, y + h / 2 + 1); p.addPoint(x + w, y); p.addPoint(x + w, y + h); g.fillPolygon(p); }
private Polygon rectToPolygon(Rectangle r) { Polygon poly = new Polygon(); poly.addPoint(r.x, r.y); poly.addPoint(r.x, r.y + r.height); poly.addPoint(r.x + r.width, r.y + r.height); poly.addPoint(r.x + r.width, r.y); return poly; }
private Polygon outline(int x, int y, double direction) { Polygon shape = new Polygon(); shape.addPoint(x, y); addPointRelative(shape, x, y, getOuterRadius(), direction - getAngle()); addPointRelative(shape, x, y, getInnerRadius(), direction); addPointRelative(shape, x, y, getOuterRadius(), direction + getAngle()); shape.addPoint(x, y); // Closing the polygon (TEG 97-04-23) return shape; }
/** * Cree un triangle. * * @param coordX coordonnee x du centre du triangle * @param coordY coordonnee y du centre du triangle * @param base taille de la base du triangle * @return polygone correspondant a un triangle */ private Polygon creeTriangle(int coordX, int coordY, int base) { Polygon p = new Polygon(); int hauteur = (int) (1.2 * base); p.addPoint(coordX - base / 2, coordY + hauteur / 2); p.addPoint(coordX + base / 2, coordY + hauteur / 2); p.addPoint(coordX, coordY - hauteur / 2); return p; }
// p0 p1 // p3 p2 private void init() { int x2 = x1 + width; int y2 = y1 + height; p.addPoint(x1, y1); p.addPoint(x2, y1); p.addPoint(x2, y2); p.addPoint(x1, y2); centroid = Mat3.centroid(p); setPose(0, 1, 1); }
/** Constructs the ship. */ public Ship(long _money, int _health, int _lives, int _posX, int _posY) { money = _money; health = _health; maxHealth = health; lives = _lives; score = 0; armed = ShipShot.LONG_SHOT; autofireRate = 30; posX = _posX; posY = _posY; weapons = new boolean[ShipShot.NUMBER_OF_WEAPONS]; for (int i = 0; i < weapons.length; i++) weapons[i] = false; weapons[0] = true; weapons[2] = true; shipShape = new LinkedList<Polygon>(); bodyShape = new Polygon(); bodyShape.addPoint(posX, posY); bodyShape.addPoint(posX + WIDTH, posY); bodyShape.addPoint(posX + WIDTH, posY + 12); bodyShape.addPoint(posX + WIDTH + 4, posY + 20); bodyShape.addPoint(posX - 4, posY + 20); bodyShape.addPoint(posX, posY + 12); shipShape.add(bodyShape); headShape = new Polygon(); headShape.addPoint(posX, posY); headShape.addPoint(posX + WIDTH, posY); headShape.addPoint(posX + WIDTH / 2, posY - 5); shipShape.add(headShape); }
/** * Update the dimensions of the arrow head, creating a new arrow head if necessary. The return * value is also set as the member variable <code>m_arrowHead</code> * * @param w the width of the untransformed arrow head base, in pixels * @param h the height of the untransformed arrow head, in pixels * @return the untransformed arrow head shape */ private Polygon updateArrowHead(int w, int h) { if (m_arrowHead == null) { m_arrowHead = new Polygon(); } else { m_arrowHead.reset(); } m_arrowHead.addPoint(0, 0); m_arrowHead.addPoint(-w / 2, -h); m_arrowHead.addPoint(w / 2, -h); m_arrowHead.addPoint(0, 0); return m_arrowHead; }
/** * Return border shape for {@code side} as if the border has zero interior length. Shape start is * at (0,0); points are added clockwise. */ private Polygon getBorderShape(int side) { Polygon shape = null; int[] widths = getWidths(); if (widths[side] != 0) { shape = new Polygon(new int[4], new int[4], 0); shape.addPoint(0, 0); shape.addPoint(-widths[(side + 3) % 4], -widths[side]); shape.addPoint(widths[(side + 1) % 4], -widths[side]); shape.addPoint(0, 0); } return shape; }
public static Polygon getArrowHead(int xFrom, int yFrom, int x, int y) { double aDir = Math.atan2(xFrom - x, yFrom - y); Polygon tmpPoly = new Polygon(); double i1 = 9; // + (int) (stroke * 2); double i2 = 4.5; // + (int) stroke; tmpPoly.addPoint(x, y); // arrow tip tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip return tmpPoly; }
private void drawArrow(Graphics2D g2d, int x1, int y1, int x2, int y2, float stroke) { double aDir = Math.atan2(x1 - x2, y1 - y2); g2d.setStroke(new BasicStroke(1f)); Polygon tmpPoly = new Polygon(); int i1 = 12 + (int) (stroke * 2); int i2 = 6 + (int) stroke; tmpPoly.addPoint(x2, y2); tmpPoly.addPoint(x2 + xCor(i1, aDir + .5), y2 + yCor(i1, aDir + .5)); tmpPoly.addPoint(x2 + xCor(i2, aDir), y2 + yCor(i2, aDir)); tmpPoly.addPoint(x2 + xCor(i1, aDir - .5), y2 + yCor(i1, aDir - .5)); tmpPoly.addPoint(x2, y2); g2d.fillPolygon(tmpPoly); }
@Override protected ImageIcon createIcon(final Color color) { RoundRectangle2D r = new RoundRectangle2D.Float(2, 5, 14, 10, 4, 4); Polygon p = new Polygon(); p.addPoint(2, 8); p.addPoint(2, 5); p.addPoint(4, 3); p.addPoint(8, 3); p.addPoint(10, 5); p.addPoint(10, 8); return IconGenerator.generateIcon(color, SIZE, SIZE, r, p); }
/** {@inheritDoc} */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double( x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? // WARN_COLOR : ALERT_COLOR); g2.draw(area); } }
public Polygon[] getBounds() { if (validate()) { final Point p = getAbsoluteLocation(); final int w = getWidth(); final int h = getHeight(); final Polygon poly = new Polygon(); poly.addPoint(p.x, p.y); poly.addPoint(p.x + w, p.y); poly.addPoint(p.x + w, p.y + h); poly.addPoint(p.x, p.y + h); return new Polygon[] {poly}; } return new Polygon[0]; }
private void drawShape(Graphics graphics) { graphics.setColor(spaceship.getColor()); Polygon shape1 = new Polygon(); Polygon shape2 = new Polygon(); float[][] shape = spaceship.getShape(); for (int i = 0; i < 4; i++) { shape1.addPoint((int) shape[i][0], (int) shape[i][1]); } for (int i = 4; i < 7; i++) { shape2.addPoint((int) shape[i][0], (int) shape[i][1]); } graphics.fillPolygon(shape1); graphics.setColor(Color.BLACK); graphics.fillPolygon(shape2); }
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); }
public LinePanel() { p = new Polygon(); p.addPoint(nextX, nextY); addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: nextY -= step; break; case KeyEvent.VK_DOWN: nextY += step; break; case KeyEvent.VK_LEFT: nextX -= step; break; case KeyEvent.VK_RIGHT: nextX += step; break; } p.addPoint(nextX, nextY); repaint(); } }); }
public void printLoop(int n, float x[], float y[]) { // Need to swap the y component Polygon P = new Polygon(); for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i])); poly_draw.add(P); poly_draw_color.add(curColor); }
/** * 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