Java Code Examples for java.awt.Graphics.drawPolygon()

The following are Jave code examples for showing how to use drawPolygon() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Rescue-Victims   File: EnvView.java   View Source Code Vote up 7 votes
public void drawSingleAgent(Graphics g, Position pos, Color color) {
    int[] xPoint = null;
    int[] yPoint = null;
    int x = pos.getX(), y = pos.getY();
    String heading = pos.getHeading();
    if (heading.equals(UP)) {
        xPoint = new int[] { x * cellSizeW, (x + 1) * cellSizeW, (int) ((0.5 + x) * cellSizeW) };
        yPoint = new int[] { (y + 1) * cellSizeH, (y + 1) * cellSizeH, y * cellSizeH };
    } else if (heading.equals(DOWN)) {
        xPoint = new int[] { x * cellSizeW, (x + 1) * cellSizeW, (int) ((0.5 + x) * cellSizeW) };
        yPoint = new int[] { y * cellSizeH, y * cellSizeH, (y + 1) * cellSizeH };
    } else if (heading.equals(LEFT)) {
        xPoint = new int[] { (x + 1) * cellSizeW, (x + 1) * cellSizeW, x * cellSizeW };
        yPoint = new int[] { y * cellSizeH, (y + 1) * cellSizeH, (int) ((0.5 + y) * cellSizeH) };
    } else if (heading.equals(RIGHT)) {
        xPoint = new int[] { x * cellSizeW, x * cellSizeW, (x + 1) * cellSizeW };
        yPoint = new int[] { y * cellSizeH, (y + 1) * cellSizeH, (int) ((0.5 + y) * cellSizeH) };
    }
    g.setColor(color);
    g.fillPolygon(new Polygon(xPoint, yPoint, 3));
    g.setColor(BOUND_COLOR);
    g.drawPolygon(new Polygon(xPoint, yPoint, 3));
}
 
Example 2
Project: Logisim   File: ComponentIcon.java   View Source Code Vote up 7 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 3
Project: MTG-Card-Recognizer   File: WebcamCanvas.java   View Source Code Vote up 6 votes
public void drawContours(Graphics g)
{
	List<Contour> contours = FindCardCandidates.getCannyContours(lastDrawn);
	for(Contour con:contours)
	{
		int[] xpoint = new int[con.external.size()];
		int[] ypoint = new int[con.external.size()];
		int i=0;
		for(Point2D_I32 pt:con.external)
		{
			xpoint[i]=pt.x;
			ypoint[i]=pt.y;
			i++;
		}
		g.drawPolygon(xpoint,ypoint,xpoint.length);
	}
}
 
Example 4
Project: Logisim   File: Poly.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, HandleGesture gesture) {
	List<Handle> hs = getHandles(gesture);
	int[] xs = new int[hs.size()];
	int[] ys = new int[hs.size()];
	int i = -1;
	for (Handle h : hs) {
		i++;
		xs[i] = h.getX();
		ys[i] = h.getY();
	}

	if (setForFill(g)) {
		g.fillPolygon(xs, ys, xs.length);
	}
	if (setForStroke(g)) {
		if (closed)
			g.drawPolygon(xs, ys, xs.length);
		else
			g.drawPolyline(xs, ys, xs.length);
	}
}
 
Example 5
Project: Logisim   File: Plexers.java   View Source Code Vote up 6 votes
static void drawTrapezoid(Graphics g, Bounds bds, Direction facing, int facingLean) {
	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 };
	int[] yp = { y0, y0, y1, y1 };
	if (facing == Direction.WEST) {
		yp[0] += facingLean;
		yp[3] -= facingLean;
	} else if (facing == Direction.NORTH) {
		xp[0] += facingLean;
		xp[1] -= facingLean;
	} else if (facing == Direction.SOUTH) {
		xp[2] -= facingLean;
		xp[3] += facingLean;
	} else {
		yp[1] += facingLean;
		yp[2] -= facingLean;
	}
	GraphicsUtil.switchToWidth(g, 2);
	g.drawPolygon(xp, yp, 4);
}
 
Example 6
Project: The-Kraken-Pathfinding   File: DStarLiteNode.java   View Source Code Vote up 6 votes
@Override
public void print(Graphics g, GraphicPanel f)
{
	if(heuristiqueOrientation != null)
	{
		double n = 40;
		XY_RW point1 = new XY_RW(n, 0), point2 = new XY_RW(-n / 2, n / 2), point3 = new XY_RW(-n / 2, -n / 2);
		point1.rotate(heuristiqueOrientation).plus(node.position);
		point2.rotate(heuristiqueOrientation).plus(node.position);
		point3.rotate(heuristiqueOrientation).plus(node.position);
		int[] X = { f.XtoWindow((int) point1.getX()), f.XtoWindow((int) point2.getX()), f.XtoWindow((int) point3.getX()) };
		int[] Y = { f.YtoWindow((int) point1.getY()), f.YtoWindow((int) point2.getY()), f.YtoWindow((int) point3.getY()) };

		g.drawPolygon(X, Y, 3);
	}
}
 
Example 7
Project: VASSAL-src   File: MenuScroller.java   View Source Code Vote up 5 votes
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 8
Project: LivroJavaComoProgramar10Edicao   File: PolygonsJPanel.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 

   // draw polygon with Polygon object
   int[] xValues = {20, 40, 50, 30, 20, 15};
   int[] yValues = {50, 50, 60, 80, 80, 60};
   Polygon polygon1 = new Polygon(xValues, yValues, 6);
   g.drawPolygon(polygon1);

   // draw polylines with two arrays
   int[] xValues2 = {70, 90, 100, 80, 70, 65, 60};
   int[] yValues2 = {100, 100, 110, 110, 130, 110, 90};
   g.drawPolyline(xValues2, yValues2, 7);

   // fill polygon with two arrays
   int[] xValues3 = {120, 140, 150, 190};
   int[] yValues3 = {40, 70, 80, 60};
   g.fillPolygon(xValues3, yValues3, 4);

   // draw filled polygon with Polygon object
   Polygon polygon2 = new Polygon();
   polygon2.addPoint(165, 135);
   polygon2.addPoint(175, 150);
   polygon2.addPoint(270, 200);
   polygon2.addPoint(200, 220);
   polygon2.addPoint(130, 180);
   g.fillPolygon(polygon2);
}
 
Example 9
Project: jaer   File: MenuScroller.java   View Source Code Vote up 5 votes
@Override
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 10
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    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.drawPolygon(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 11
Project: Cognizant-Intelligent-Test-Scripter   File: MenuScroller.java   View Source Code Vote up 5 votes
@Override
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 12
Project: jdk8u-jdk   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    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.drawPolygon(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 13
Project: openjdk-jdk10   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    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.drawPolygon(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 14
Project: The-Kraken-Pathfinding   File: Cinematique.java   View Source Code Vote up 5 votes
@Override
public void print(Graphics g, GraphicPanel f)
{
	double n = 40;
	XY_RW point1 = new XY_RW(n, 0), point2 = new XY_RW(-n / 2, n / 2), point3 = new XY_RW(-n / 2, -n / 2);
	point1.rotate(orientationGeometrique).plus(position);
	point2.rotate(orientationGeometrique).plus(position);
	point3.rotate(orientationGeometrique).plus(position);
	int[] X = { f.XtoWindow((int) point1.getX()), f.XtoWindow((int) point2.getX()), f.XtoWindow((int) point3.getX()) };
	int[] Y = { f.YtoWindow((int) point1.getY()), f.YtoWindow((int) point2.getY()), f.YtoWindow((int) point3.getY()) };

	g.drawPolygon(X, Y, 3);
}
 
Example 15
Project: The-Kraken-Pathfinding   File: RectangularObstacle.java   View Source Code Vote up 5 votes
@Override
public void print(Graphics g, GraphicPanel f)
{
	int[] X = new int[4];
	X[0] = (int) coinBasDroiteRotate.getX();
	X[1] = (int) coinHautDroiteRotate.getX();
	X[2] = (int) coinHautGaucheRotate.getX();
	X[3] = (int) coinBasGaucheRotate.getX();

	int[] Y = new int[4];
	Y[0] = (int) coinBasDroiteRotate.getY();
	Y[1] = (int) coinHautDroiteRotate.getY();
	Y[2] = (int) coinHautGaucheRotate.getY();
	Y[3] = (int) coinBasGaucheRotate.getY();

	for(int i = 0; i < 4; i++)
	{
		X[i] = f.XtoWindow(X[i]);
		Y[i] = f.YtoWindow(Y[i]);
	}
	g.drawPolygon(X, Y, 4);
	
	Color c = g.getColor();
	Color cTransparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 30);
	g.setColor(cTransparent);
	
	g.fillPolygon(X, Y, 4);
}
 
Example 16
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
* This function draw the area among the axis and the point of the convex hull
 * @param g The graphic object
 * @param allConvex The vector with the points of the convex hull
 * @param allDominants The vector with the dominant points
 * @param area The filter area
 * @param maskedoff The vector with the masked-off points
 */
public void drawArea(Graphics g, Vector<Point2D> allConvex, Vector<Point2D> allDominants, Color area, Color maskedoff) {
	//The first color in the maskedoff color because after will be draw
	//the non-maskedoff areas
	g.setColor(maskedoff);
	Polygon poly = new Polygon();

	DPoint p;
	p = (DPoint) allConvex.get(0);

	poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y);

	//Add the point a the polygon for paint the convex area
	for (int i = 0; i < allConvex.size(); i++) {
		p = (DPoint) allConvex.get(i);
		poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
	}

	p = (DPoint) allConvex.get(allConvex.size() - 1);
	poly.addPoint(1 + tran_x, tran_y - (int) (p.getY() * scale));
	poly.addPoint(1 + tran_x, tran_y);
	g.fillPolygon(poly);
	g.setColor(Color.GRAY);
	g.drawPolygon(poly);

	//Draw the non-maskedoff area for each dominant point
	Polygon masked = new Polygon();
	g.setColor(area);

	int k = 0;
	for (k = 0; k < allDominants.size() - 1; k++) {
		p = (DPoint) allDominants.get(k);
		if (!p.intEquals((DPoint) allDominants.get(k + 1))) {
			masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
			g.fillPolygon(masked);
		}
	}
	//Last area is 1 point small
	p = (DPoint) allDominants.get(k);
	masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale) + 1);
	g.fillPolygon(masked);
}
 
Example 17
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
* This function draw te area among the axis and the point of the convex hull
 * @param g The graphic object
 * @param allConvex The vector with the points of the convex hull
 * @param allDominants The vector with the dominant points
 * @param area The filter area
 * @param maskedoff The vector with the masked-off points
 */
public void drawArea(Graphics g, Vector<Point2D> allConvex, Vector<Point2D> allDominants, Color area, Color maskedoff) {
	//The first color in the maskedoff color beacause after will be draw
	//the non-maskedoff areas
	g.setColor(maskedoff);
	Polygon poly = new Polygon();

	DPoint p;
	p = (DPoint) allConvex.get(0);

	poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y);

	//Add the point a the polygon for paint the convex area
	for (int i = 0; i < allConvex.size(); i++) {
		p = (DPoint) allConvex.get(i);
		poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
	}

	p = (DPoint) allConvex.get(allConvex.size() - 1);
	poly.addPoint(1 + tran_x, tran_y - (int) (p.getY() * scale));
	poly.addPoint(1 + tran_x, tran_y);
	g.fillPolygon(poly);
	g.setColor(Color.GRAY);
	g.drawPolygon(poly);

	//Draw the non-maskedoff area for each dominant point
	Polygon masked = new Polygon();
	g.setColor(area);

	int k = 0;
	for (k = 0; k < allDominants.size() - 1; k++) {
		p = (DPoint) allDominants.get(k);
		if (!p.intEquals((DPoint) allDominants.get(k + 1))) {
			masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
			g.fillPolygon(masked);
		}
	}
	//Last area is 1 point small
	p = (DPoint) allDominants.get(k);
	masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale) + 1);
	g.fillPolygon(masked);
}
 
Example 18
Project: Equella   File: DecisionRenderer.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	final int centreX = (int) bounds.getCenterX();

	// Draw the leading arrow
	drawLeadingInArrow(g, centreX, bounds.y, HALF_ARROW_HEIGHT);

	// Draw the trailing arrow
	drawLeadingOutArrow(g, centreX, bounds.y + bounds.height - HALF_ARROW_HEIGHT, HALF_ARROW_HEIGHT);

	// Get ready to draw our child
	Dimension childSize = super.getSizeWithNoPadding(g);
	Rectangle childBound = new Rectangle();
	childBound.x = centreX - (childSize.width / 2);
	childBound.y = bounds.y + (HALF_ARROW_HEIGHT * 2) + DIAMOND_SIZE;
	childBound.width = childSize.width;
	childBound.height = childSize.height;

	// Draw child
	super.draw(g, childBound);

	// Do some general calculations
	Rectangle2D textSize = g.getFontMetrics().getStringBounds(nodeName, g);

	int diamondTop = bounds.y + HALF_ARROW_HEIGHT;
	int halfDiamondY = DIAMOND_SIZE / 2;
	int halfDiamondX = (int) (textSize.getWidth() / 2) + (PADDING_SIZE * 2);

	int textStartX = centreX - (int) (textSize.getWidth() / 2);
	int textStartY = diamondTop + halfDiamondY + (int) (textSize.getHeight() / 2);

	// Draw the diamond
	int[] pointsX = {centreX, centreX - halfDiamondX, centreX, centreX + halfDiamondX};
	int[] pointsY = {diamondTop, diamondTop + halfDiamondY, diamondTop + DIAMOND_SIZE, diamondTop + halfDiamondY};

	if( getHilight() != null )
	{
		g.setColor(getHilight());
		g.fillPolygon(pointsX, pointsY, pointsX.length);
	}

	g.setColor(Color.BLACK);
	g.drawPolygon(pointsX, pointsY, pointsX.length);

	// Draw the text
	g.setColor(Color.BLACK);
	g.drawString(nodeName, textStartX, textStartY - 3);

	// Draw the arrow leading out from the diamond
	drawLeadingOutArrow(g, centreX, diamondTop + DIAMOND_SIZE, HALF_ARROW_HEIGHT);

	// Draw connecting lines
	int lineX1 = centreX - (childSize.width / 2) - PADDING_SIZE;
	int lineX2 = centreX - halfDiamondX;
	int lineY1 = diamondTop + halfDiamondY;
	int lineY2 = lineY1 + HALF_ARROW_HEIGHT + halfDiamondY + childSize.height;

	lineX1 = Math.min(lineX1, lineX2);

	g.setColor(ARROW_COLOUR);
	g.drawLine(lineX1, lineY1, lineX2, lineY1);
	g.drawLine(lineX1, lineY2, centreX, lineY2);
	g.drawLine(lineX1, lineY1, lineX1, lineY2);

	// Draw sideways pointer on arrow
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 - ARROW_HEAD_WIDTH, centreX, lineY2);
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 + ARROW_HEAD_WIDTH, centreX, lineY2);
}