Example usage for org.apache.poi.hssf.usermodel EscherGraphics2d drawPolygon

List of usage examples for org.apache.poi.hssf.usermodel EscherGraphics2d drawPolygon

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel EscherGraphics2d drawPolygon.

Prototype

public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) 

Source Link

Usage

From source file:poi.hssf.usermodel.examples.OfficeDrawingWithGraphics.java

License:Apache License

private static void drawStar(EscherGraphics2d g2d) {
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (double i = 0; i < Math.PI; i += 0.1) {
        g2d.setColor(new Color((int) (i * 5343062d)));
        int x1 = (int) (Math.cos(i) * 160.0) + 160;
        int y1 = (int) (Math.sin(i) * 138.0) + 138;
        int x2 = (int) (-Math.cos(i) * 160.0) + 160;
        int y2 = (int) (-Math.sin(i) * 138.0) + 138;
        g2d.setStroke(new BasicStroke(2));
        g2d.drawLine(x1, y1, x2, y2);/*from   w ww .j  a va2 s. c  o  m*/
    }
    g2d.setFont(new Font("SansSerif", Font.BOLD | Font.ITALIC, 20));
    g2d.drawString("EscherGraphics2d", 70, 100);
    g2d.setColor(Color.yellow);
    g2d.fillOval(160 - 20, 138 - 20, 40, 40);
    g2d.setColor(Color.black);
    g2d.fillPolygon(new int[] { -10 + 160, 0 + 160, 10 + 160, 0 + 160 },
            new int[] { 0 + 138, 10 + 138, 0 + 138, -10 + 138 }, 4);
    g2d.drawPolygon(new int[] { -160 + 160, 0 + 160, 160 + 160, 0 + 160 },
            new int[] { 0 + 138, 138 + 138, 0 + 138, -138 + 138 }, 4);
}