Java Code Examples for java.awt.Graphics#fillPolygon()
The following examples show how to use
java.awt.Graphics#fillPolygon() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentIcon.java From Logisim with GNU General Public License v3.0 | 6 votes |
@Override public void paintIcon(java.awt.Component c, Graphics g, int x, int y) { // draw tool icon Graphics gIcon = g.create(); ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon); comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet()); gIcon.dispose(); if (triangleState != TRIANGLE_NONE) { int[] xp; int[] yp; if (triangleState == TRIANGLE_CLOSED) { xp = new int[] { x + 13, x + 13, x + 17 }; yp = new int[] { y + 11, y + 19, y + 15 }; } else { xp = new int[] { x + 11, x + 19, x + 15 }; yp = new int[] { y + 13, y + 13, y + 17 }; } g.setColor(Color.LIGHT_GRAY); g.fillPolygon(xp, yp, 3); g.setColor(Color.DARK_GRAY); g.drawPolygon(xp, yp, 3); } }
Example 2
Source File: SimulationTreeRenderer.java From Logisim with GNU General Public License v3.0 | 6 votes |
@Override public void paintIcon(Component c, Graphics g, int x, int y) { ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, g); factory.paintIcon(context, x, y, factory.createAttributeSet()); // draw magnifying glass if appropriate if (isCurrentView) { int tx = x + 13; int ty = y + 13; int[] xp = { tx - 1, x + 18, x + 20, tx + 1 }; int[] yp = { ty + 1, y + 20, y + 18, ty - 1 }; g.setColor(ProjectExplorer.MAGNIFYING_INTERIOR); g.fillOval(x + 5, y + 5, 10, 10); g.setColor(Color.BLACK); g.drawOval(x + 5, y + 5, 10, 10); g.fillPolygon(xp, yp, xp.length); } }
Example 3
Source File: OldGoldenSpiral.java From IngressAnimations with GNU General Public License v3.0 | 6 votes |
private void drawSquare(Graphics gr, int square, Scale scale, double frac) { gr.setColor(colors[MathUtils.mod(square,colors.length)]); int index = MathUtils.mod(square, 4); int power = (square-index)/4; double[][] pp = base[index]; double[][] qq = base[index+1]; double multiple = Math.pow(3*p+2,power); int[] ix = new int[4]; int[] iy = new int[4]; for (int i=0; i<4; i++) { double x = (pp[i][0]*(1-frac) + qq[i][0]*frac)*multiple; double y = (pp[i][1]*(1-frac) + qq[i][1]*frac)*multiple; int[] ixy = scale.toGraphics(x, y); ix[i] = ixy[0]; iy[i] = ixy[1]; } gr.fillPolygon(ix, iy, 4); }
Example 4
Source File: ColorIcon.java From openAGV with Apache License 2.0 | 5 votes |
@Override public void paintIcon(Component c, Graphics g, int x, int y) { //Graphics2D g = (Graphics2D) gr; if (fillColor == null || fillColor.getAlpha() == 0) { if (width == noColorImage.getWidth() && height == noColorImage.getHeight()) { g.drawImage(noColorImage, x, y, c); } else { g.setColor(Color.WHITE); g.fillRect(x + 1, y + 1, width - 2, height - 2); g.setColor(Color.red); int[] xpoints = new int[] {x + 2, x + width - 5, x + width - 3, x + width - 3, x + 4, x + 2}; int[] ypoints = new int[] {y + height - 5, y + 2, y + 2, y + 4, y + height - 3, y + height - 3}; g.fillPolygon(xpoints, ypoints, xpoints.length); } } else { // g.setColor(Color.WHITE); // g.fillRect(x + 1, y + 1, width - 2, height - 2); g.setColor(fillColor); // g.fillRect(x + 2, y + 2, width - 4, height - 4); g.fillRect(x + 1, y + 1, width - 2, height - 2); } g.setColor(new Color(0x666666)); // Draw the rectangle using drawLine to work around a drawing bug in // Apples MRJ for Java 1.5 // g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1); g.drawLine(x, y, x + width - 1, y); g.drawLine(x + width - 1, y, x + width - 1, y + width - 1); g.drawLine(x + width - 1, y + height - 1, x, y + height - 1); g.drawLine(x, y + height - 1, x, y); }
Example 5
Source File: C3Sprite.java From megamek with GNU General Public License v2.0 | 5 votes |
@Override public void drawOnto(Graphics g, int x, int y, ImageObserver observer) { Polygon drawPoly = new Polygon(c3Poly.xpoints, c3Poly.ypoints, c3Poly.npoints); drawPoly.translate(x, y); g.setColor(spriteColor); g.fillPolygon(drawPoly); g.setColor(Color.black); g.drawPolygon(drawPoly); }
Example 6
Source File: BasicIconFactory.java From Bytecoder with Apache License 2.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x+getIconWidth(), y+getIconHeight()/2); p.addPoint(x, y+getIconHeight()); g.fillPolygon(p); }
Example 7
Source File: RenderTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { RenderTests.Context rctx = (RenderTests.Context) ctx; int size = rctx.size; int x = rctx.initX; int y = rctx.initY; int hexaX[] = new int[6]; int hexaY[] = new int[6]; Graphics g = rctx.graphics; g.translate(rctx.orgX, rctx.orgY); Color rCArray[] = rctx.colorlist; int ci = rctx.colorindex; do { hexaX[0] = x; hexaX[1] = hexaX[5] = x+size/4; hexaX[2] = hexaX[4] = x+size-size/4; hexaX[3] = x+size; hexaY[1] = hexaY[2] = y; hexaY[0] = hexaY[3] = y+size/2; hexaY[4] = hexaY[5] = y+size; if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.fillPolygon(hexaX, hexaY, 6); if ((x -= 3) < 0) x += rctx.maxX; if ((y -= 1) < 0) y += rctx.maxY; } while (--numReps > 0); rctx.colorindex = ci; g.translate(-rctx.orgX, -rctx.orgY); }
Example 8
Source File: RenderTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { RenderTests.Context rctx = (RenderTests.Context) ctx; int size = rctx.size; int x = rctx.initX; int y = rctx.initY; int hexaX[] = new int[6]; int hexaY[] = new int[6]; Graphics g = rctx.graphics; g.translate(rctx.orgX, rctx.orgY); Color rCArray[] = rctx.colorlist; int ci = rctx.colorindex; do { hexaX[0] = x; hexaX[1] = hexaX[5] = x+size/4; hexaX[2] = hexaX[4] = x+size-size/4; hexaX[3] = x+size; hexaY[1] = hexaY[2] = y; hexaY[0] = hexaY[3] = y+size/2; hexaY[4] = hexaY[5] = y+size; if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.fillPolygon(hexaX, hexaY, 6); if ((x -= 3) < 0) x += rctx.maxX; if ((y -= 1) < 0) y += rctx.maxY; } while (--numReps > 0); rctx.colorindex = ci; g.translate(-rctx.orgX, -rctx.orgY); }
Example 9
Source File: PMSimplePolygonArea.java From megamek with GNU General Public License v2.0 | 5 votes |
public void drawInto(Graphics g) { if ((g == null) || (!visible)) return; Color oldColor = g.getColor(); g.setColor(this.backColor); g.fillPolygon(areaShape); if (selected && highlight) { g.setColor(highlightBorderColor); } else { g.setColor(this.normalBorderColor); } g.drawPolygon(this.areaShape); g.setColor(oldColor); }
Example 10
Source File: ComplexSurfacePlot.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Draws the base plane. The base plane is the x-y plane. * * @param g the graphics context to draw. * @param x used to retrieve x coordinates of drawn plane from this method. * @param y used to retrieve y coordinates of drawn plane from this method. */ private final void drawBase(Graphics g, int[] x, int[] y) { Point projection = projector.project(-10, -10, -10); x[0] = projection.x; y[0] = projection.y; projection = projector.project(-10, 10, -10); x[1] = projection.x; y[1] = projection.y; projection = projector.project(10, 10, -10); x[2] = projection.x; y[2] = projection.y; projection = projector.project(10, -10, -10); x[3] = projection.x; y[3] = projection.y; x[4] = x[0]; y[4] = y[0]; if(plot_mode!=ColorMapper.WIREFRAME) { if(plot_mode==ColorMapper.NORENDER) { g.setColor(Color.lightGray); } else { g.setColor(new Color(192, 220, 192)); } g.fillPolygon(x, y, 4); } g.setColor(Color.black); g.drawPolygon(x, y, 5); }
Example 11
Source File: RenderTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { RenderTests.Context rctx = (RenderTests.Context) ctx; int size = rctx.size; int x = rctx.initX; int y = rctx.initY; int hexaX[] = new int[6]; int hexaY[] = new int[6]; Graphics g = rctx.graphics; g.translate(rctx.orgX, rctx.orgY); Color rCArray[] = rctx.colorlist; int ci = rctx.colorindex; do { hexaX[0] = x; hexaX[1] = hexaX[5] = x+size/4; hexaX[2] = hexaX[4] = x+size-size/4; hexaX[3] = x+size; hexaY[1] = hexaY[2] = y; hexaY[0] = hexaY[3] = y+size/2; hexaY[4] = hexaY[5] = y+size; if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.fillPolygon(hexaX, hexaY, 6); if ((x -= 3) < 0) x += rctx.maxX; if ((y -= 1) < 0) y += rctx.maxY; } while (--numReps > 0); rctx.colorindex = ci; g.translate(-rctx.orgX, -rctx.orgY); }
Example 12
Source File: WorldView.java From jason with GNU Lesser General Public License v3.0 | 5 votes |
public void drawGold(Graphics g, int x, int y) { g.setColor(Color.yellow); g.drawRect(x * cellSizeW + 2, y * cellSizeH + 2, cellSizeW - 4, cellSizeH - 4); int[] vx = new int[4]; int[] vy = new int[4]; vx[0] = x * cellSizeW + (cellSizeW / 2); vy[0] = y * cellSizeH; vx[1] = (x + 1) * cellSizeW; vy[1] = y * cellSizeH + (cellSizeH / 2); vx[2] = x * cellSizeW + (cellSizeW / 2); vy[2] = (y + 1) * cellSizeH; vx[3] = x * cellSizeW; vy[3] = y * cellSizeH + (cellSizeH / 2); g.fillPolygon(vx, vy, 4); }
Example 13
Source File: PlotColorUtilityColours.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
public static void main(String[] args) { final Color[] colours = PlotColorUtility.GRAPH_DEFAULT_COLORS; final int width = 300; final int spacing = 40; final int height = spacing * (colours.length + 1); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // white background g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); // show each colour for (int i=0; i<colours.length; i++) { final Color c = colours[i]; g.setColor(c); final int y = spacing * (i+1); // line g.drawLine(0, y, width, y); // triangle Polygon p = new Polygon(); p.addPoint(width/2, y); p.addPoint(width, y-10); p.addPoint(width, y+10); g.fillPolygon(p); // RGB values final String text = String.format("%d: (%d, %d, %d)", i, c.getRed(), c.getGreen(), c.getBlue()); g.drawString(text, 20, y-4); } JLabel label = new JLabel(new ImageIcon(image)); JFrame frame = new JFrame(PlotColorUtility.class.getSimpleName() + " colours"); frame.add(label); frame.pack(); frame.setLocation(300, 300); frame.setVisible(true); }
Example 14
Source File: CSSBorder.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ? getShadowColor(color) : getLightColor(color)); g.fillPolygon(shape); }
Example 15
Source File: CSSBorder.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ? getShadowColor(color) : getLightColor(color)); g.fillPolygon(shape); }
Example 16
Source File: MiniMap.java From megamek with GNU General Public License v2.0 | 4 votes |
/** * Draw a line to represent an attack */ private void paintAttack(Graphics g, AttackAction attack) { Entity source = m_game.getEntity(attack.getEntityId()); Targetable target = m_game.getTarget(attack.getTargetType(), attack.getTargetId()); // sanity check... if ((null == source) || (null == target)) { return; } if (attack.getTargetType() == Targetable.TYPE_INARC_POD) { // iNarc pods don't have a position, so lets scrap this idea, shall // we? return; } if (attack instanceof WeaponAttackAction) { WeaponAttackAction waa = (WeaponAttackAction) attack; if ((attack.getTargetType() == Targetable.TYPE_HEX_ARTILLERY) && (waa.getEntity(m_game).getOwner().getId() != m_client .getLocalPlayer().getId())) { return; } } Color oldColor = g.getColor(); int[] xPoints = new int[4]; int[] yPoints = new int[4]; xPoints[0] = ((source.getPosition().getX() * (hexSide[zoom] + hexSideBySin30[zoom])) + leftMargin + ((int) 1.5 * hexSide[zoom])) - 2; yPoints[0] = (((2 * source.getPosition().getY()) + 1 + (source .getPosition().getX() % 2)) * hexSideByCos30[zoom]) + topMargin; xPoints[1] = ((target.getPosition().getX() * (hexSide[zoom] + hexSideBySin30[zoom])) + leftMargin + ((int) 1.5 * hexSide[zoom])) - 2; yPoints[1] = (((2 * target.getPosition().getY()) + 1 + (target .getPosition().getX() % 2)) * hexSideByCos30[zoom]) + topMargin; xPoints[2] = xPoints[1] + 2; xPoints[3] = xPoints[0] + 2; if (((source.getPosition().getX() > target.getPosition().getX()) && (source .getPosition().getY() < target.getPosition().getY())) || ((source.getPosition().getX() < target.getPosition().getX()) && (source .getPosition().getY() > target.getPosition().getY()))) { yPoints[3] = yPoints[0] + 2; yPoints[2] = yPoints[1] + 2; } else { yPoints[3] = yPoints[0] - 2; yPoints[2] = yPoints[1] - 2; } g.setColor(PlayerColors.getColor(source.getOwner().getColorIndex())); g.fillPolygon(xPoints, yPoints, 4); g.setColor(Color.black); g.drawPolygon(xPoints, yPoints, 4); // if this is mutual fire, draw a half-and-half line for (Enumeration<EntityAction> iter = m_game.getActions(); iter .hasMoreElements();) { EntityAction action = iter.nextElement(); if (action instanceof AttackAction) { AttackAction otherAttack = (AttackAction) action; if ((attack.getEntityId() == otherAttack.getTargetId()) && (otherAttack.getEntityId() == attack.getTargetId())) { // attackTarget _must_ be an entity since it's shooting back // (?) Entity attackTarget = m_game.getEntity(otherAttack .getEntityId()); g.setColor(PlayerColors.getColor(attackTarget.getOwner() .getColorIndex())); xPoints[0] = xPoints[3]; yPoints[0] = yPoints[3]; xPoints[1] = xPoints[2]; yPoints[1] = yPoints[2]; xPoints[2] = xPoints[1] + 2; xPoints[3] = xPoints[0] + 2; if (((source.getPosition().getX() > target.getPosition() .getX()) && (source.getPosition().getY() < target .getPosition().getY())) || ((source.getPosition().getX() < target .getPosition().getX()) && (source .getPosition().getY() > target .getPosition().getY()))) { yPoints[3] = yPoints[0] + 2; yPoints[2] = yPoints[1] + 2; } else { yPoints[3] = yPoints[0] - 2; yPoints[2] = yPoints[1] - 2; } g.fillPolygon(xPoints, yPoints, 4); g.setColor(Color.black); g.drawPolygon(xPoints, yPoints, 4); break; } } } g.setColor(oldColor); }
Example 17
Source File: CSSBorder.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(color); g.fillPolygon(shape); }
Example 18
Source File: BasicSection.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean render (Graphics g, boolean drawBorders) { Rectangle clip = g.getClipBounds(); Rectangle rect = getBounds(); Color oldColor = g.getColor(); if (clip.intersects(rect)) { // Default section color Color color = isVertical() ? Colors.GRID_VERTICAL : Colors.GRID_HORIZONTAL; // Use color defined for section glyph shape, if any Glyph glyph = getGlyph(); if (glyph != null) { Shape shape = glyph.getShape(); if (shape != null) { color = shape.getColor(); } } g.setColor(color); // Fill polygon with proper color Polygon polygon = getPolygon(); g.fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); // Draw polygon borders if so desired if (drawBorders) { g.setColor(Color.black); g.drawPolygon( polygon.xpoints, polygon.ypoints, polygon.npoints); } g.setColor(oldColor); return true; } else { return false; } }
Example 19
Source File: CSSBorder.java From Bytecoder with Apache License 2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(color); g.fillPolygon(shape); }
Example 20
Source File: CSSBorder.java From Bytecoder with Apache License 2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ? getShadowColor(color) : getLightColor(color)); g.fillPolygon(shape); }