Path2D.Double curve = new Path2D.Double(); Arc2D innerarc = new Arc2D.Double(x + 1, y - 197 * eh / 700 + 1, ew - 2, eh - 2, 0, 360, Arc2D.OPEN); curve.append(new Rectangle2D.Double(x, y, x2 - x, y2 - y), false); g2.setClip(new Rectangle2D.Double(x, y, x2 - x, y2 - y)); g2.setClip(arc); Rectangle2D r = curve.getBounds2D(); g2.drawImage(artToUse, x, y, x2 - x, y2 - y, null); g2.setClip(null); g2.setClip(new Rectangle2D.Double(x, y, x2 - x, y2 - y));
DriverLineG2d.manageStroke(param, g2d); final Path2D.Double p = new Path2D.Double(); boolean hasBezier = false; final MinMaxDouble minMax = new MinMaxDouble(); final double coord[] = seg.getCoord(); if (type == USegmentType.SEG_MOVETO) { p.moveTo(x + coord[0], y + coord[1]); minMax.manage(x + coord[0], y + coord[1]); } else if (type == USegmentType.SEG_LINETO) { p.lineTo(x + coord[0], y + coord[1]); minMax.manage(x + coord[0], y + coord[1]); } else if (type == USegmentType.SEG_CUBICTO) { p.curveTo(x + coord[0], y + coord[1], x + coord[2], y + coord[3], x + coord[4], y + coord[5]); minMax.manage(x + coord[4], y + coord[5]); hasBezier = true; p.closePath(); g2d.setColor(mapper.getMappedColor(param.getColor())); g2d.fill(p); return; (float) minMax.getMaxX(), (float) minMax.getMaxY(), mapper.getMappedColor(gr.getColor2())); g2d.setPaint(paint); g2d.fill(p); } else if (back != null) {
Shape donutSlice = PlotContent_Pie.getDonutSliceShape(pieBounds, donutThickness, startAngle, totalAngle); g.setColor(donutColorArr[i]); g.fill(donutSlice); g.draw(donutSlice); double yOffset = yCenter - Math.sin(radians) * (yDiameter * arrowLengthPercentage); Path2D.Double path = new Path2D.Double(); if (styler.isToolTipsEnabled()) { String annotation = series.getAnnotation(); path.moveTo(xCenter, yCenter); xOffset = xCenter + Math.cos(radians) * (xDiameter * diameterPerct); yOffset = yCenter - Math.sin(radians) * (yDiameter * diameterPerct); path.lineTo(xOffset, yOffset); path.closePath(); g.setColor(series.getFillColor()); g.fill(path);
private static final Color ROSE_COLOR = Color.red; private static final Stroke ROSE_STROKE = new BasicStroke(8f); private Path2D path = new Path2D.Double(); double dY = SCALE * r * Math.sin(theta) + DELTA_Y; if (i == 0) { path.moveTo(dX, dY); } else { path.lineTo(dX, dY); path.closePath(); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(ROSE_COLOR); g2.setStroke(ROSE_STROKE); g2.draw(path); RosePanel mainPanel = new RosePanel(); JFrame frame = new JFrame("RosePanel"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
protected void paintComponent(Graphics graphics) { super.paintComponent(graphics); Path2D.Double path = new Path2D.Double(); Graphics2D g = (Graphics2D) graphics; path.moveTo(17, 63); path.curveTo(21, 60, 21, 43, 17, 37); //left vert path.curveTo(30, 43, 100, 43, 120, 37); //top horiz path.curveTo(115, 45, 115, 57, 117, 62); //right vert path.curveTo(105, 53, 60, 57, 17, 63); //bottom horiz right path.moveTo(32, 97); path.curveTo(37, 85, 35, 79, 35, 77); //left vert path.curveTo(45, 79, 45, 79, 100, 79); //top left horiz path.curveTo(96, 85, 98, 92, 98, 98);//right vert path.curveTo(89, 93, 79, 94, 32, 97);//bottom right horiz path.moveTo(40, 130); path.curveTo(48, 110, 46, 70, 37, 55); //left vert path.curveTo(62, 55, 62, 55, 60, 55); //top horiz path.curveTo(68, 80, 68, 100, 63, 130); //right vert path.curveTo(60, 127, 50, 127, 40, 130);//bottom horiz g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setStroke(new BasicStroke(3));
private static final int PREF_H = 700; private static final Color SHAPE_COLOR = new Color(255, 100, 100); private Path2D myShape = new Path2D.Double(); myShape.append(new Ellipse2D.Double(150, 50, 200, 200), true); myShape.append(new Rectangle2D.Double(150, 150, 200, 400), true); myShape.append(new Ellipse2D.Double(350, 250, 150, 150), true); myShape.append(new Ellipse2D.Double(150, 450, 200, 200), true); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (myShape != null) { g2.setColor(SHAPE_COLOR); g2.fill(myShape); DragShape mainPanel = new DragShape(); JFrame frame = new JFrame("DragShape"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
private static final Color COLOR_2 = Color.red; private static final Paint GRADIENT_PAINT = new GradientPaint(0, 0, COLOR_1, 20, 20, COLOR_2, true); private Path2D myPath = new Path2D.Double(); double firstY = 3.0 * PREF_H / 4.0; myPath.moveTo(firstX, firstY); myPath.lineTo(PREF_W - firstX, firstY); myPath.lineTo(PREF_W / 2.0, PREF_H / 4.0); myPath.closePath(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(GRADIENT_PAINT); // just for fun! g2.fill(myPath); // fill my triangle Path2DExample mainPanel = new Path2DExample(); JFrame frame = new JFrame("Path2DExample"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new ShapeOutlineTestPanel()); f.setSize(500, 500); f.setLocationRelativeTo(null); f.setVisible(true); g.setStroke(traceStroke); g.setColor(Color.BLUE); g.drawPolyline(xs, ys, 6); Path2D path = new Path2D.Double(); for (int i = 0; i < xs.length; i++) path.moveTo(xs[i], ys[i]); path.lineTo(xs[i], ys[i]); g.setColor(Color.RED); BasicStroke stroke = new BasicStroke( 10.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); g.draw(new Area(stroke.createStrokedShape(path)));
Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getColor()); g2d.setStroke(getStroke()); Path2D path = buildPath(points); g2d.draw(path); g2d.dispose(); Path2D path = new Path2D.Double(); if (points != null && points.size() > 0) { Point firstPoint = points.get(0); path.moveTo(firstPoint.getX(), firstPoint.getY()); for (Point p : points) { path.lineTo(p.getX(), p.getY()); JFrame frame = new JFrame("Demo"); JMapViewer viewer = new JMapViewer(); viewer.addMapPolygon(polyLine); frame.add(viewer); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.fill(poly); g2d.setColor(Color.GREEN); g2d.translate(50, 100); g2d.fill(triangleShape); g2d.dispose(); moveTo(points[0].getX(), points[0].getY()); lineTo(points[1].getX(), points[1].getY()); lineTo(points[2].getX(), points[2].getY()); closePath();
@SuppressWarnings("serial") public static void main(String[] args) { JFrame f = new JFrame("Test"); JPanel c = new JPanel() { Area a; Path2D p; p = new Path2D.Double(); p.append(new CubicCurve2D.Double(0, 0, 100, 0, 150, 50, 200, 100), true); p.append(new CubicCurve2D.Double(200, 100, 200, 150, 150,0, 50, 100), true); p.append(new CubicCurve2D.Double(100, 100, 100, 50, 50, 50, 0, 0), true); a = new Area(p); setPreferredSize(new Dimension(300, 300)); g.setColor(Color.black); ((Graphics2D)g).fill(p); System.out.println(a.isSingular()); f.setContentPane(c); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true);
JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().setLayout(new BorderLayout()); f.getContentPane().add(new SpiralDrawPanel(),BorderLayout.CENTER); f.setSize(800, 800); f.setLocationRelativeTo(null); f.setVisible(true); BasicStroke.JOIN_MITER, 10.0f, new float[]{10.0f}, 0.0f); g.setStroke(stroke); Shape shape = at.createTransformedShape( createArchimedeanSpiral(Math.PI*10, 10, 250)); g.draw(shape); double totalAngleRad, double alpha, int steps) Path2D path = new Path2D.Double(); path.moveTo(0, 0); double angleDeltaRad = totalAngleRad / steps; for (int i=0; i<=steps; i++) double x = Math.sin(angleRad) * alpha * angleRad; double y = Math.cos(angleRad) * alpha * angleRad; path.lineTo(x, y);
Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2d.setStroke(new BasicStroke(4)); double x = (getWidth() - arrow.getBounds().getWidth()) / 2d; double y = (getHeight() - arrow.getBounds().getHeight()) / 2d; at.rotate(theta, arrow.getBounds().getWidth() / 2d, arrow.getBounds().getHeight() / 2d); g2d.setTransform(at); g2d.draw(arrow); g2d.dispose(); moveTo(0, 10); lineTo(36, 10); moveTo(36 - 16, 0); lineTo(36, 10); moveTo(36 - 16, 20); lineTo(36, 10);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); int x = (getWidth() - diamond.getBounds().width) / 2; int y = (getHeight()- diamond.getBounds().height) / 2; AffineTransform at = AffineTransform.getTranslateInstance(x, y); Shape shape = at.createTransformedShape(diamond); g2d.setColor(Color.YELLOW); g2d.fill(shape); g2d.setColor(Color.RED); g2d.draw(shape); g2d.dispose(); moveTo(0, height / 2); lineTo(width / 2, 0); lineTo(width, height / 2); lineTo(width / 2, height); closePath();
g.setColor(Color.RED); ((Graphics2D) g).fill(bend); Path2D.Double bend2 = new Path2D.Double(); bend2.moveTo(0, 50); bend2.quadTo(0, 0, 50, 0); bend2.lineTo(50, 25); bend2.quadTo(25, 25, 25, 50); bend2.closePath(); g.setColor(Color.GREEN); ((Graphics2D) g).fill(bend2); Area bend3 = new Area(outerArc); bend3.subtract(new Area(innerArc)); g.setColor(Color.BLUE); ((Graphics2D) g).fill(bend3); @Override public void run() { JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(new TestDonut()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
BasicStroke stroke = new BasicStroke(1); Shape strokedShape = stroke.createStrokedShape(shape); g2.draw(strokedShape); g2.fill(strokedShape); Path2D path = new Path2D.Double(); shape = path; path.moveTo(start.x, start.y); path.lineTo(stop.x, stop.y); shape = path; start = stop; Path2D path = (Path2D) shape; try { path.closePath(); } catch(Exception ingore) { PenDemoPanel shapes = new PenDemoPanel(); JFrame frame = new JFrame("PenDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(shapes); frame.pack(); frame.setVisible(true);
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.WHITE); g.fillRect(0, 0, 100, 100); g.setColor(Color.BLACK); g.setStroke(new BasicStroke(2)); Path2D path = new Path2D.Double(); path.moveTo(-92, 37); path.lineTo(88, 39); g.draw(path); g.dispose(); ImageIO.write(image, "png", new File("output.png"));
slider.setValue(100); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tp); frame.add(slider, BorderLayout.SOUTH); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setTransform(AffineTransform.getTranslateInstance(x, y)); g2d.draw(shape); g2d.dispose(); moveTo(width / 2, 0); lineTo(width, height / 3d); lineTo((width / 5d) * 4, height); lineTo((width / 5d), height); lineTo(0, height / 3d); closePath();
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); shape = new Path2D.Double(); shape.moveTo(0, 0); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.draw(shape); g2d.dispose(); int x = currentPoint.x + xDelta; int y = currentPoint.y + yDelta; shape.lineTo(x, y); currentPoint.x = x; currentPoint.y = y;
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); moveTo(54, 0); lineTo(66, 36); lineTo(108, 36); lineTo(75, 54); lineTo(82, 96); lineTo(54, 72); lineTo(26, 96); lineTo(36, 54); lineTo(0, 36); lineTo(42, 36); closePath(); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); Rectangle bounds = starShape.getBounds(); int x = (getWidth() - bounds.width) / 2; int y = (getHeight() - bounds.height) / 2; g2d.fill(starShape.createTransformedShape(AffineTransform.getTranslateInstance(x, y))); g2d.dispose();