public boolean mutate() { copyImage(_lastGeneration, _tempGeneration); int centerX = _random.nextInt(_smallWidth); int centerY = _random.nextInt(_smallHeight); for (int id = 0; id < 4; id++) { _xs[id] = (int) (centerX + _random.nextInt(_smallWidth) * X_SIGNS[id] * _random.nextDouble()); _ys[id] = (int) (centerY + _random.nextInt(_smallWidth) * Y_SIGNS[id] * _random.nextDouble()); } Color color = new Color( _random.nextInt(256), _random.nextInt(256), _random.nextInt(256), _random.nextInt(256)); _tempGfx.setColor(color); _tempGfx.fillPolygon(_xs, _ys, 4); long fitness = _comparer.compare(_tempGeneration); if (fitness <= _lastFitness) { _lastFitness = fitness; copyImage(_tempGeneration, _lastGeneration); for (int i = 0; i < 4; i++) { _xs[i] /= SCALE; _ys[i] /= SCALE; } _finalGfx.setColor(color); _finalGfx.fillPolygon(_xs, _ys, 4); return true; } else return false; }
private void fillPolyline(int x[], int y[], int length, int symbolType) { if (!Preferences.monochrome) { setFillColor(symbolType); gRef.fillPolygon(x, y, length); restoreColor(); } }
private void drawPolygon(LineSegment s0, LineSegment s1) throws TransformException { worldToGrid(s0.p0, 0); worldToGrid(s0.p1, 1); worldToGrid(s1.p1, 2); worldToGrid(s1.p0, 3); graphics.fillPolygon(px, py, 4); }
public BufferedImage generateImageFromDna( List<Gene> dna, GAParameters parameters, double multiplier) { // long timestamp = System.currentTimeMillis(); BufferedImage image = new BufferedImage( (int) (parameters.getTargetImage().getWidth() * multiplier), (int) (parameters.getTargetImage().getHeight() * multiplier), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); drawBlackBackground(graphics, parameters, multiplier); for (Gene gene : dna) { int[] x = new int[gene.getPoints().size()]; int[] y = new int[gene.getPoints().size()]; for (int i = 0; i < gene.getPoints().size(); i++) { x[i] = (int) (gene.getPoints().get(i).getX() * multiplier); y[i] = (int) (gene.getPoints().get(i).getY() * multiplier); } Polygon p = new Polygon(x, y, gene.getPoints().size()); graphics.setColor(gene.getColor()); graphics.fillPolygon(p); } // System.out.println("rendering took : " + (System.currentTimeMillis() - timestamp)); return image; }
private void drawArrow(final int zoom, final Graphics2D g) { BasicStroke pen = new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); Polygon p = new Polygon(); double peakLength = 0.4; double tailThickness = 0.1; double length = 10 + (zoom - 15) * 10 / 4; double height = 4 + (zoom - 15) * 3 / 4; int ycenter = -(int) height / 2; p.addPoint( (int) (length * peakLength), (int) (ycenter + (height - (height * tailThickness)) / 2)); p.addPoint((int) (length), (int) (ycenter + (height - (height * tailThickness)) / 2)); p.addPoint((int) (length), ycenter); p.addPoint((int) ((length) + (length * peakLength)), (int) height / 2 + ycenter); p.addPoint((int) (length), (int) height + ycenter); p.addPoint( (int) (length), (int) (ycenter + (height - (height * tailThickness)) / 2 + (height * tailThickness))); p.addPoint( (int) (length * peakLength), (int) (ycenter + (height - (height * tailThickness)) / 2 + (height * tailThickness))); g.setStroke(pen); g.fillPolygon(p); g.drawPolygon(p); }
// 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 drawMathObject(PolygonObject object, Graphics g, Point pageOrigin, float zoomLevel) { g.setColor(Color.BLACK); ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness()); Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(sap.getLineThickness())); Polygon p = new Polygon(); GridPoint[] points = object.getAdjustedVertices(); for (int i = 0; i < points.length; i++) { p.addPoint( (int) (points[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (points[i].gety() * sap.getHeight()) + sap.getyOrigin()); } if (object.getColor() != null) { g2d.setColor(object.getColor()); g2d.fillPolygon(p); g2d.setColor(Color.BLACK); } g2d.drawPolygon(p); g2d.setStroke(new BasicStroke(1)); }
/** * This method provides the implementation for rendering polygons. Note that it will go through * and render each part. */ public void render( Graphics2D g2, double zoomScale, double viewportCenterX, double viewportCenterY, int panelWidth, int panelHeight) { // FOR ALL PARTS (POLYGONS) for (int a = 0; a < numParts; a++) { // DETERMINE HOW MANY POINTS ARE IN THIS PART int size = calculateSize(a); // AND FILL OUR POINTS ARRAYS WITH DATA this.fillData( a, size, xRenderData, yRenderData, zoomScale, viewportCenterX, viewportCenterY, panelWidth, panelHeight); // THEN USE THEM TO RENDER g2.setColor(fillColor); g2.fillPolygon(xRenderData, yRenderData, size); g2.setColor(lineColor); g2.drawPolygon(xRenderData, yRenderData, size); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); int[] x = new int[3]; int[] y = new int[3]; double distance = startPoint.distance(endPoint); double halfDistance = distance / 2; double angle = -Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x); System.out.println(angle); x[0] = (int) endPoint.getX(); y[0] = (int) endPoint.getY(); x[1] = (int) ((Math.sin(angle) * halfDistance) + startPoint.getX()); y[1] = (int) ((Math.cos(angle) * halfDistance) + startPoint.getY()); x[2] = (int) (startPoint.getX() - (Math.sin(angle) * halfDistance)); y[2] = (int) (startPoint.getY() - (Math.cos(angle) * halfDistance)); g2d.setColor(Color.RED); g2d.fillPolygon(x, y, 3); g2d.setColor(Color.BLUE); g2d.fillOval(startPoint.x - 5, startPoint.y - 5, 10, 10); g2d.setColor(Color.GREEN); g2d.fillOval(endPoint.x - 5, endPoint.y - 5, 10, 10); g2d.dispose(); }
// don't override update(), get the default clear public void paint(Graphics g) { // if (log.isTraceEnabled()) // log.trace("paint(): hovering=" + hovering); Graphics2D g2 = (Graphics2D) g; if (rapid_evolution.RapidEvolution.aaEnabled) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color color = this.color; if (color == null) color = SkinManager.instance.getColor("moreinfo_spin_color"); Color hoverColor = this.hoverColor; if (hoverColor == null) hoverColor = SkinManager.instance.getColor("moreinfo_spin_hovering_color"); ; g2.setColor(hovering ? hoverColor : color); if (isOpen()) g2.fillPolygon(openTriangle); else g2.fillPolygon(closedTriangle); }
@Override public void paintLayer(Graphics2D g) { g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setColor(new Color(0, 0, 255, 120)); for (Polygon w : waters) { g.drawPolygon(w); g.fillPolygon(w); } g.setColor(new Color(0, 255, 0, 120)); for (Polygon l : lands) { g.drawPolygon(l); g.fillPolygon(l); } }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(new Color(0, 224, 0)); g2.fillPolygon(px, py, 4); g2.setColor(Color.BLACK); g2.drawPolygon(px, py, 4); }
public void paint(Graphics gOld) { if (image == null || xsize != getSize().width || ysize != getSize().height) { xsize = getSize().width; ysize = getSize().height; image = createImage(xsize, ysize); g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // fill background g.setColor(Color.cyan); g.fillRect(0, 0, xsize, ysize); int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)}; int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)}; // fill border g.setColor(Color.black); g.fillPolygon(x, y, 4); // draw border g.setColor(Color.red); g.drawPolyline(x, y, 5); if (animateFirstTime) { gOld.drawImage(image, 0, 0, null); return; } if (gameOver) return; g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this); for (int index = 0; index < missile.length; index++) { if (missile[index].active) { g.setColor(Color.red); drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5); } } if (rocketRight) { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0); } else { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0); } for (int index = 0; index < numStars; index++) { g.setColor(Color.yellow); if (starActive[index]) drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5); } g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Score: " + score, 10, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("HighScore: " + highScore, 300, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Lives: " + rocketLife, 150, 45); if (rocketLife == 0) { g.setColor(Color.red); g.setFont(new Font("Impact", Font.BOLD, 60)); g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2)); } gOld.drawImage(image, 0, 0, null); }
private void paintCaret(Graphics2D g_) { EditorImpl.CaretRectangle[] locations = myEditor.getCaretLocations(true); if (locations == null) return; Graphics2D g = IdeBackgroundUtil.getOriginalGraphics(g_); int lineHeight = myView.getLineHeight(); EditorSettings settings = myEditor.getSettings(); Color caretColor = myEditor.getColorsScheme().getColor(EditorColors.CARET_COLOR); if (caretColor == null) caretColor = new JBColor(CARET_DARK, CARET_LIGHT); g.setColor(caretColor); for (EditorImpl.CaretRectangle location : locations) { int x = location.myPoint.x; int y = location.myPoint.y; Caret caret = location.myCaret; boolean isRtl = location.myIsRtl; if (myEditor.isInsertMode() != settings.isBlockCursor()) { int lineWidth = JBUI.scale(settings.getLineCursorWidth()); g.fillRect(x, y, lineWidth, lineHeight); if (myDocument.getTextLength() > 0 && caret != null && !myView.getLineLayout(caret.getLogicalPosition().line).isLtr()) { g.fillPolygon( new int[] { isRtl ? x + lineWidth : x, isRtl ? x + lineWidth - CARET_DIRECTION_MARK_SIZE : x + CARET_DIRECTION_MARK_SIZE, isRtl ? x + lineWidth : x }, new int[] {y, y, y + CARET_DIRECTION_MARK_SIZE}, 3); } } else { int width = location.myWidth; int startX = Math.max(0, isRtl ? x - width : x); g.fillRect(startX, y, width, lineHeight - 1); if (myDocument.getTextLength() > 0 && caret != null) { int targetVisualColumn = caret.getVisualPosition().column; for (VisualLineFragmentsIterator.Fragment fragment : VisualLineFragmentsIterator.create(myView, caret.getVisualLineStart(), false)) { int startVisualColumn = fragment.getStartVisualColumn(); int endVisualColumn = fragment.getEndVisualColumn(); if (startVisualColumn < targetVisualColumn && endVisualColumn > targetVisualColumn || startVisualColumn == targetVisualColumn && !isRtl || endVisualColumn == targetVisualColumn && isRtl) { g.setColor(ColorUtil.isDark(caretColor) ? CARET_LIGHT : CARET_DARK); fragment.draw( g, startX, y + myView.getAscent(), targetVisualColumn - startVisualColumn - (isRtl ? 1 : 0), targetVisualColumn - startVisualColumn + (isRtl ? 0 : 1)); break; } } } } } }
private static void paintSelectedBottom(Graphics g, int x, int y, int w, int h) { g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[1]); g.drawLine(x + 11, y + h - 1, x + w - 12, y + h - 1); g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[2]); g.drawLine(x + 10, y + h - 2, x + w - 11, y + h - 2); g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[3]); g.drawLine(x + 13, y + h - 1, x + w - 14, y + h - 1); ColorUIResource c1 = RapidLookTools.getColors().getTabbedPaneColors()[4]; g.setColor(c1); // left g.drawLine(x + 9, y + h - 2, x + 9, y + h - 3); g.drawLine(x + 8, y + h - 3, x + 8, y + h - 3); g.drawLine(x + 7, y + h - 3, x + 7, y + h - 4); g.drawLine(x + 6, y + h - 4, x + 6, y + h - 5); g.drawLine(x + 5, y + h - 5, x + 5, y + h - 6); // right g.drawLine(w + x - 10, y + h - 2, w + x - 10, y + h - 3); g.drawLine(w + x - 9, y + h - 3, w + x - 9, y + h - 3); g.drawLine(w + x - 8, y + h - 3, w + x - 8, y + h - 4); g.drawLine(w + x - 7, y + h - 4, w + x - 7, y + h - 5); g.drawLine(w + x - 6, y + h - 5, w + x - 6, y + h - 6); // inner section g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[5]); g.drawLine(x + 10, y + h - 3, x + w - 11, y + h - 3); g.drawLine(x + 8, y + h - 4, x + w - 9, y + h - 4); g.drawLine(x + 7, y + h - 5, x + w - 8, y + h - 5); g.drawLine(x + 6, y + h - 6, x + w - 7, y + h - 6); Graphics2D g2 = (Graphics2D) g; g2.setPaint( new GradientPaint( 1, y, RapidLookTools.getColors().getTabbedPaneColors()[7], 1, y + h - 6, RapidLookTools.getColors().getTabbedPaneColors()[6])); int[] xArr = new int[] {x + 4, w + x - 5, x + w - 1, x}; int[] yArr = new int[] {y + h - 6, y + h - 6, y, y}; Polygon p1 = new Polygon(xArr, yArr, 4); g2.fillPolygon(p1); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setColor(c1); g2.drawLine(x, y, x + 4, y + h - 6); g2.drawLine(w + x - 1, y, x + w - 5, y + h - 6); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); }
@Override protected void drawImprecise( Graphics2D graphics, STRTransform transform, boolean transformUpdated) { if (transformUpdated) { transform.transformVertices(vertices, xPoints, yPoints); } if (filled) { graphics.fillPolygon(xPoints, yPoints, nVertices); } else { graphics.drawPolygon(xPoints, yPoints, nVertices); } }
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 public void draw(Graphics2D gd, double value) { int sides = 3; int[] xpoints = new int[sides]; int[] ypoints = new int[sides]; PolygonPoints p = new PolygonPoints(xpoints, ypoints, sides); p.generatePoints(value); p.setOffset(xOffset + (int) value, yOffset + (int) value); gd.setColor(Color.BLUE); gd.fillPolygon(new Polygon(xpoints, ypoints, sides)); }
private Icon buildIcon() { int height = getFontMetrics(getFont()).getHeight(); BufferedImage bi = new BufferedImage(height, height, BufferedImage.TYPE_INT_ARGB); int t = height / 2; if ((t & 0x01) > 0) ++t; int h = (height - t) / 2; int s = 0; // getInsets().left + getWidth() - RIGHT_PADDING - h - (h+RIGHT_ICON_SPACE) ; Graphics2D g = bi.createGraphics(); Environment.setBeautifulRendering(g); g.setColor(getForeground()); g.fillPolygon(new int[] {s, s + t, s}, new int[] {h, h + t / 2, h + t}, 3); return new ImageIcon(bi); }
private void paintWhitespace( Graphics2D g, CharSequence text, float x, int y, int start, int end, EditorImpl.LineWhitespacePaintingStrategy whitespacePaintingStrategy, VisualLineFragmentsIterator.Fragment fragment) { g.setColor(myEditor.getColorsScheme().getColor(EditorColors.WHITESPACES_COLOR)); boolean isRtl = fragment.isRtl(); int baseStartOffset = fragment.getStartOffset(); int startOffset = isRtl ? baseStartOffset - start : baseStartOffset + start; for (int i = start; i < end; i++) { int charOffset = isRtl ? baseStartOffset - i - 1 : baseStartOffset + i; char c = text.charAt(charOffset); if (" \t\u3000".indexOf(c) >= 0 && whitespacePaintingStrategy.showWhitespaceAtOffset(charOffset)) { int startX = (int) fragment.offsetToX( x, startOffset, isRtl ? baseStartOffset - i : baseStartOffset + i); int endX = (int) fragment.offsetToX( x, startOffset, isRtl ? baseStartOffset - i - 1 : baseStartOffset + i + 1); if (c == ' ') { g.fillRect((startX + endX) / 2, y, 1, 1); } else if (c == '\t') { endX -= myView.getPlainSpaceWidth() / 4; int height = myView.getCharHeight(); int halfHeight = height / 2; int mid = y - halfHeight; int top = y - height; UIUtil.drawLine(g, startX, mid, endX, mid); UIUtil.drawLine(g, endX, y, endX, top); g.fillPolygon( new int[] {endX - halfHeight, endX - halfHeight, endX}, new int[] {y, y - height, y - halfHeight}, 3); } else if (c == '\u3000') { // ideographic space final int charHeight = myView.getCharHeight(); g.drawRect(startX + 2, y - charHeight, endX - startX - 4, charHeight); } } } }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g; g2.setPaint(Color.BLACK); g2.translate(x, y); int[] xPoints = {6, 2, 6}; int[] yPoints = {2, 6, 6}; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawPolygon(xPoints, yPoints, 3); g2.fillPolygon(xPoints, yPoints, 3); g2.translate(-x, -y); }
private void drawArrow(Graphics2D g2, int x1, int y1, int x2, int y2) { final double len = 8.0; double slopy = Math.atan2(y2 - y1, x2 - x1); double cosy = Math.cos(slopy); double siny = Math.sin(slopy); int[] xPoints = { 0, x2, 0 }; int[] yPoints = { 0, y2, 0 }; double a = len * siny, b = len * cosy; double c = len / 2.0 * siny, d = len / 2.0 * cosy; xPoints[0] = x2 - (int) (b + c); yPoints[0] = y2 - (int) (a - d); xPoints[2] = x2 - (int) (b - c); yPoints[2] = y2 - (int) (d + a); g2.fillPolygon(xPoints, yPoints, 3); }
private static void paintSelectedLeft(Graphics g, int x, int y, int w, int h) { g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[2]); g.drawLine(x + 10, y + 1, x + w - 1, y + 1); g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[3]); g.drawLine(x + 11, y, x + w - 1, y); ColorUIResource c1 = RapidLookTools.getColors().getTabbedPaneColors()[4]; g.setColor(c1); g.drawLine(x + 9, y + 1, x + 9, y + 2); g.drawLine(x + 8, y + 2, x + 8, y + 2); g.drawLine(x + 7, y + 2, x + 7, y + 3); g.drawLine(x + 6, y + 3, x + 6, y + 4); g.drawLine(x + 5, y + 4, x + 5, y + 5); g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[5]); g.drawLine(x + 10, y + 2, x + w - 5, y + 2); g.drawLine(x + 8, y + 3, x + w - 5, y + 3); g.drawLine(x + 7, y + 4, x + w - 5, y + 4); g.drawLine(x + 6, y + 5, x + w - 5, y + 5); Graphics2D g2 = (Graphics2D) g; g2.setPaint( new GradientPaint( 1, y + 6, RapidLookTools.getColors().getTabbedPaneColors()[6], 1, y + h, RapidLookTools.getColors().getTabbedPaneColors()[7])); int[] xArr = new int[] {x + 4, w + x - 5, w + x - 5, x + 4}; int[] yArr = new int[] {y + 6, y + 6, y + h, y + h}; Polygon p1 = new Polygon(xArr, yArr, 4); g2.fillPolygon(p1); g.setColor(c1); g.drawLine(x + 4, y + 6, x + 4, y + h - 1); g.setColor(RapidLookTools.getColors().getTabbedPaneColors()[1]); g.drawLine(x + 11, y, x + 13, y); g.drawLine(x + 5, y + 6, x + 5, y + 6); }
// Taken from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135 public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y) { Graphics2D g2d = (Graphics2D) g; double aDir = Math.atan2(xCenter - x, yCenter - y); // g2d.drawLine(x, y, xCenter, yCenter); g2d.setStroke( new BasicStroke(1f)); // make the arrow head solid even if dash pattern has been specified Polygon tmpPoly = new Polygon(); int i1 = 12; int i2 = 6; // make the arrow head the same size regardless of the length length tmpPoly.addPoint(x, y); // arrow tip tmpPoly.addPoint(x + xCor(i1, aDir + 0.5), y + yCor(i1, aDir + 0.5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - 0.5), y + yCor(i1, aDir - 0.5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted }
public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g; g2d.setPaint(Color.black); iconHeight = g2d.getFontMetrics().getHeight() + 1; iconWidth = g2d.getFontMetrics().stringWidth(label) + 1; int baseText = g2d.getFontMetrics().getAscent(); g2d.drawString(label, x, y + baseText); int shiftx = x + iconWidth + 1; int shifty = y + baseText - 5; int[] xPoints = {shiftx, shiftx + 8, shiftx + 4}; int[] yPoints = {shifty, shifty, shifty + 4}; // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.fillPolygon(xPoints, yPoints, xPoints.length); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_DEFAULT); }
/** Fill polygon. The coordinates are in logical coordinates. */ public void fillPolygon(double[]... coord) { int[][] c = new int[coord.length][2]; for (int i = 0; i < coord.length; i++) { c[i] = projection.screenProjection(coord[i]); } int[] x = new int[c.length]; for (int i = 0; i < c.length; i++) { x[i] = c[i][0]; } int[] y = new int[c.length]; for (int i = 0; i < c.length; i++) { y[i] = c[i][1]; } g2d.fillPolygon(x, y, c.length); }
void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) { Graphics2D g = (Graphics2D) g1.create(); double dx = x2 - x1, dy = y2 - y1; double angle = Math.atan2(dy, dx); int len = (int) Math.sqrt(dx * dx + dy * dy); AffineTransform at = AffineTransform.getTranslateInstance(x1, y1); at.concatenate(AffineTransform.getRotateInstance(angle)); g.transform(at); // Draw horizontal arrow starting in (0, 0) g.drawLine(0, 0, len, 0); g.fillPolygon( new int[] {len, len - ARR_SIZE, len - ARR_SIZE, len}, new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4); }
/** @see SimpleMarker#paintMarker(java.lang.Object) */ @Override protected Area paintMarker(T context) { int width = image.getWidth(); int height = image.getHeight(); if (height > maxHeight) { float shrink = (float) maxHeight / (float) height; height = maxHeight; width = (int) (width * shrink); } int x = -width / 2; int y = -height / 2; // create graphics for image plus one pixel border Graphics2D g = beginPainting(width + 2, height + 2, width / 2 + 1, height / 2 + 1); try { g.drawImage( image, x, y, x + width, y + height, 0, 0, image.getWidth(), image.getHeight(), null); // shadow if (!hasAlpha(image)) { g.setColor(new Color(0, 0, 0, 180)); // g.setColor((selected)?(new Color(200, 0, 0, 180)):(new // Color(0, 0, 200, 180))); g.fillPolygon( new int[] {x + 3, x + width, x + width, x + width + 3, x + width + 3, x + 3}, new int[] {y + height, y + height, y + 3, y + 3, y + height + 3, y + height + 3}, 6); } // selection if (context.isSelected()) { g.setColor(Color.RED); g.drawRect(x - 1, y - 1, width + 1, height + 1); } } finally { endPainting(g); } return new BoxArea(x, y, x + width, y + height); }
/** * Updates the arrow. * * @param x * @param y * @param dir */ public void updateArrow(Coord coords) { Graphics2D surface = currentScreen.createGraphics(); Polygon arrow = getArrow(coords); int mapHeight = ((mapLevel.getHeight() - 1) * ImageBank.FEATUREHEIGHT); // Redraw this square. surface.drawImage( createSquare(mapLevel.getMapSquare(coords)), null, coords.getX() * ImageBank.FEATUREWIDTH, mapHeight - (coords.getY() * ImageBank.FEATUREHEIGHT)); // Overlay the arrow. surface.setColor(Color.RED); surface.fillPolygon(arrow); surface.setColor(Color.WHITE); surface.drawPolygon(arrow); surface.dispose(); }
@Override public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) { Color f = cpool.getColor(color.x, color.y, color.z, .4f); Color s = cpool.getColor(color.x, color.y, color.z, 1f); Graphics2D g = getGraphics(); saveState(g); int[] xInts = xIntsPool.get(vertexCount); int[] yInts = yIntsPool.get(vertexCount); for (int i = 0; i < vertexCount; i++) { getWorldToScreenToOut(vertices[i], temp); xInts[i] = (int) temp.x; yInts[i] = (int) temp.y; } g.setStroke(stroke); g.setColor(f); g.fillPolygon(xInts, yInts, vertexCount); g.setColor(s); g.drawPolygon(xInts, yInts, vertexCount); restoreState(g); }