List of usage examples for java.awt Graphics drawPolyline
public abstract void drawPolyline(int[] xPoints, int[] yPoints, int nPoints);
From source file:GraphicsUtil.java
static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) { double offs = headAngle * Math.PI / 180.0; double angle = Math.atan2(y0 - y1, x0 - x1); int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1, x1 + (int) (headLength * Math.cos(angle - offs)) }; int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1, y1 + (int) (headLength * Math.sin(angle - offs)) }; g.drawLine(x0, y0, x1, y1);// w w w. ja v a 2 s . c om g.drawPolyline(xs, ys, 3); }
From source file:Main.java
public void paint(Graphics g) { int[] xs = { 25, 75, 125, 85, 125, 75, 25, 65 }; int[] ys = { 50, 90, 50, 100, 150, 110, 150, 100 }; g.drawPolyline(xs, ys, 8); }
From source file:MainClass.java
public void paint(Graphics g) { int[] xs = { 25, 75, 125, 85, 125, 75, 25, 65 }; int[] ys = { 50, 90, 50, 100, 150, 110, 150, 100 }; g.drawPolyline(xs, ys, 8); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); int[] x = { 0, 100, 100, 0, 0, 75, 75, 125, 25, 50 }; int[] y = { 0, 10, 10, 100, 25, 125, 75, 75, 510, 50 }; Graphics2D g2d = (Graphics2D) g; AffineTransform at0 = g2d.getTransform(); g2d.scale(size / 100, size / 100);/*from w w w . jav a 2s .com*/ g.drawPolyline(x, y, x.length); g2d.setTransform(at0); }
From source file:Main.java
protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawLine(10, 100, 380, 100);// w w w.j a v a 2 s.c om g.drawLine(200, 30, 200, 190); g.drawLine(380, 100, 370, 90); g.drawLine(380, 100, 370, 110); g.drawLine(200, 30, 190, 40); g.drawLine(200, 30, 210, 40); g.drawString("X", 360, 80); g.drawString("Y", 220, 40); Polygon p = new Polygon(); Polygon p2 = new Polygon(); for (int x = -170; x <= 170; x++) { p.addPoint(x + 200, 100 - (int) (50 * f((x / 100.0) * 2 * Math.PI))); } for (int x = -170; x <= 170; x++) { p2.addPoint(x + 200, 100 - (int) (50 * gCos((x / 100.0) * 2 * Math.PI))); } g.setColor(Color.red); g.drawPolyline(p.xpoints, p.ypoints, p.npoints); g.drawString("-2\u03c0", 95, 115); g.drawString("-\u03c0", 147, 115); g.drawString("\u03c0", 253, 115); g.drawString("2\u03c0", 305, 115); g.drawString("0", 200, 115); g.setColor(Color.blue); g.drawPolyline(p2.xpoints, p2.ypoints, p2.npoints); }
From source file:com.cburch.draw.shapes.Poly.java
@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;/*from ww w . j av a 2 s. com*/ 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); } }
From source file:edu.umn.cs.spatialHadoop.core.OGCESRIShape.java
public void drawESRIGeom(Graphics g, OGCGeometry geom, double xscale, double yscale) { if (geom instanceof OGCLineString) { OGCLineString linestring = (OGCLineString) geom; int[] xs = new int[linestring.numPoints()]; int[] ys = new int[linestring.numPoints()]; int n = 0; for (int i = 0; i < n; i++) { OGCPoint point = linestring.pointN(i); xs[n] = (int) Math.round(point.X() * xscale); ys[n] = (int) Math.round(point.Y() * yscale); // Increment number of point if this point is different than previous ones if (n == 0 || xs[n] != xs[n - 1] || ys[n] != ys[n - 1]) n++;/*from w ww .ja v a2 s. c o m*/ } g.drawPolyline(xs, ys, n); } else { throw new RuntimeException("Cannot draw a shape of type " + geom.getClass()); } }
From source file:edu.umn.cs.spatialHadoop.core.OGCJTSShape.java
/** * Plots a Geometry from the library JTS into the given image. * @param graphics/* w w w.ja v a2 s . co m*/ * @param geom * @param fileMbr * @param imageWidth * @param imageHeight * @param scale * @param shape_color * @deprecated - use {@link #drawJTSGeom(Graphics, Geometry, double, double)} */ @Deprecated private static void drawJTSShape(Graphics graphics, Geometry geom, Rectangle fileMbr, int imageWidth, int imageHeight, double scale, Color shape_color) { if (geom instanceof GeometryCollection) { GeometryCollection geom_coll = (GeometryCollection) geom; for (int i = 0; i < geom_coll.getNumGeometries(); i++) { Geometry sub_geom = geom_coll.getGeometryN(i); // Recursive call to draw each geometry drawJTSShape(graphics, sub_geom, fileMbr, imageWidth, imageHeight, scale, shape_color); } } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom; for (int i = 0; i < poly.getNumInteriorRing(); i++) { LineString ring = poly.getInteriorRingN(i); drawJTSShape(graphics, ring, fileMbr, imageWidth, imageHeight, scale, shape_color); } drawJTSShape(graphics, poly.getExteriorRing(), fileMbr, imageWidth, imageHeight, scale, shape_color); } else if (geom instanceof LineString) { LineString line = (LineString) geom; double geom_alpha = line.getLength() * scale; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[line.getNumPoints()]; int[] ypoints = new int[line.getNumPoints()]; for (int i = 0; i < xpoints.length; i++) { double px = line.getPointN(i).getX(); double py = line.getPointN(i).getY(); // Transform a point in the polygon to image coordinates xpoints[i] = (int) Math.round((px - fileMbr.x1) * imageWidth / fileMbr.getWidth()); ypoints[i] = (int) Math.round((py - fileMbr.y1) * imageHeight / fileMbr.getHeight()); } // Draw the polygon //graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); graphics.drawPolyline(xpoints, ypoints, xpoints.length); } }
From source file:edu.umn.cs.spatialHadoop.core.OGCJTSShape.java
/** * Draw the given JTS Geometry to the graphics using specific scales in x and y * @param g Graphics to draw to//from w w w . j a va 2s . c o m * @param geom The geometry to draw * @param xscale The scale of the x-axis in terms in pixels/units * @param yscale The scale of the y-axis in terms of pixels/units * @param fill Whether to fill the shape or just draw an outline */ public static void drawJTSGeom(Graphics g, Geometry geom, double xscale, double yscale, boolean fill) { if (geom instanceof GeometryCollection) { GeometryCollection geom_coll = (GeometryCollection) geom; for (int i = 0; i < geom_coll.getNumGeometries(); i++) { Geometry sub_geom = geom_coll.getGeometryN(i); // Recursive call to draw each geometry drawJTSGeom(g, sub_geom, xscale, yscale, fill); } } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom; for (int i = 0; i < poly.getNumInteriorRing(); i++) { LineString ring = poly.getInteriorRingN(i); drawJTSGeom(g, ring, xscale, yscale, fill); } drawJTSGeom(g, poly.getExteriorRing(), xscale, yscale, fill); } else if (geom instanceof LineString) { LineString line = (LineString) geom; double geom_alpha = line.getLength() * (xscale + yscale) / 2.0; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[line.getNumPoints()]; int[] ypoints = new int[line.getNumPoints()]; int n = 0; for (int i = 0; i < xpoints.length; i++) { double px = line.getPointN(i).getX(); double py = line.getPointN(i).getY(); // Transform a point in the polygon to image coordinates xpoints[n] = (int) Math.round(px * xscale); ypoints[n] = (int) Math.round(py * yscale); // Include this point only if first point or different than previous point if (n == 0 || xpoints[n] != xpoints[n - 1] || ypoints[n] != ypoints[n - 1]) n++; } // Draw the polygon //graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); if (n == 1) g.fillRect(xpoints[0], ypoints[0], 1, 1); else if (!fill) g.drawPolyline(xpoints, ypoints, n); else g.fillPolygon(xpoints, ypoints, n); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolySegment(Client c, XDrawable d, GC gc) throws IOException { int foo;/*from w ww . ja va 2 s . co m*/ int n = c.length; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode | GC.GCLineWidth); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } n /= 2; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { foo = c.xarray[0] = (short) c.client.readShort(); if (foo <= sx) sx = foo; if (foo >= lx) lx = foo; foo = c.yarray[0] = (short) c.client.readShort(); if (foo <= sy) sy = foo; if (foo >= ly) ly = foo; foo = c.xarray[1] = (short) c.client.readShort(); if (foo <= sx) sx = foo; if (foo >= lx) lx = foo; foo = c.yarray[1] = (short) c.client.readShort(); if (foo <= sy) sy = foo; if (foo >= ly) ly = foo; if (gc.lineWidth <= 1) graphics.drawPolyline(c.xarray, c.yarray, 2); else { if (c.yarray[0] == c.yarray[1]) { graphics.drawPolyline(c.xarray, c.yarray, 2); c.yarray[0] -= (gc.lineWidth / 2); c.yarray[1] -= (gc.lineWidth / 2); for (int i = 0; i < gc.lineWidth; i++) { graphics.drawPolyline(c.xarray, c.yarray, 2); c.yarray[0]++; c.yarray[1]++; } } else { drawThickLine(graphics, c.xarray[0], c.yarray[0], c.xarray[1], c.yarray[1], gc.lineWidth); } } n--; } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { if ((gc.attr & GC.IncludeInferiors) == 0) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } } else { ((XPixmap) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }