Search in sources :

Example 76 with Path2D

use of java.awt.geom.Path2D in project SimpleAsteroids by ljialin.

the class SearchSpaceView method paintComponent.

public void paintComponent(Graphics gx) {
    int[] randPoint = SearchSpaceUtil.randomPoint(searchSpace);
    Graphics2D g = (Graphics2D) gx;
    g.setColor(bg);
    g.fillRect(0, 0, size.width, size.height);
    // now need to work out the various sizes needed for these ...
    int n = searchSpace.nDims();
    int inset = 5;
    double yStep = (double) size.getHeight() / n;
    float colStep = 1.0f / n;
    float col = 0.1f;
    double y = 0;
    for (int i = 0; i < n; i++) {
        Path2D path = new Path2D.Double();
        path.moveTo(0, y);
        g.setColor(Color.getHSBColor(col, 1, 1));
        col += colStep;
        Shape shape = new Rectangle2D.Double(0, y, size.getWidth(), yStep);
        path.append(shape, false);
        g.fill(shape);
        g.setColor(Color.cyan);
        g.setStroke(new BasicStroke(5));
        g.draw(path);
        g.setColor(Color.black);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, (int) yStep / 4));
        // 
        // Draw Hello World String
        // 
        String paramName = searchSpace.params.get(i).name;
        int yString = (int) (y + yStep / 2 + inset * 2);
        g.drawString(paramName, (int) inset * 2, yString);
        // now iterate over all the values there
        FontMetrics fontMetrics = g.getFontMetrics();
        Rectangle2D rect = fontMetrics.getStringBounds(paramName, g);
        int x = (int) inset * 2;
        x += rect.getWidth() + inset * 2;
        double[] vec = searchSpace.params.get(i).values;
        for (int j = 0; j < vec.length; j++) {
            double val = vec[j];
            String sVal = String.format("%.1f", val);
            rect = fontMetrics.getStringBounds(sVal, g);
            rect.setRect(x, yString - rect.getHeight(), rect.getWidth(), rect.getHeight());
            if (j == randPoint[i]) {
                g.setColor(Color.white);
                // need to move the rect to the correct place
                g.fill(rect);
            // g.setColor(Color.red);
            // g.draw(rect);
            // System.out.println("Filled: " + rect);
            }
            g.setColor(Color.black);
            g.drawString(sVal, x, yString);
            // todo can do this easily
            // rect.add(x, yString);
            x += rect.getWidth() + inset * 2;
        }
        y += yStep;
        System.out.println(y);
    }
}
Also used : Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 77 with Path2D

use of java.awt.geom.Path2D in project SimpleAsteroids by ljialin.

the class LineChart method drawLegend.

private void drawLegend(Graphics2D g, Dimension size) {
    if (lineGroups == null)
        return;
    // get the string stat size stats: we need this to get the
    // size of the bounding box to be correct
    StatSummary stringLengths = new StatSummary();
    for (LineGroup lineGroup : lineGroups) {
        if (lineGroup.name != null) {
            Rectangle2D stringRect = g.getFontMetrics().getStringBounds(lineGroup.name, g);
            stringLengths.add(stringRect.getWidth());
        }
    }
    double plotWidth = plotRight - plotLeft;
    double lineLength = plotWidth / 10;
    g.setFont(new Font("Monospaced", Font.BOLD, getFontSize(size)));
    // first draw in the lines
    double gap = getFontSize(size) * 1.5;
    double top = plotBottom + gap * (lineGroups.size() + 1);
    double boxWidth = stringLengths.max() + gap + lineLength;
    double boxHeight = gap * (lineGroups.size() + 1);
    Rectangle2D.Double rect = new Rectangle2D.Double(plotRight - gap / 2 - boxWidth, plotBottom + gap / 2, boxWidth, boxHeight);
    g.setColor(new Color(255, 255, 255, 230));
    g.fill(rect);
    g.setColor(Color.black);
    g.draw(rect);
    top -= gap / 2;
    for (LineGroup lineGroup : lineGroups) {
        Path2D path = new Path2D.Double();
        double xStart = plotRight - gap - lineLength;
        path.moveTo(xStart, top);
        path.lineTo(plotRight - gap, top);
        top -= gap;
        g.setColor(lineGroup.color);
        // change this to better styles later
        g.setStroke(new BasicStroke(2));
        g.draw(path);
        if (lineGroup.name != null) {
            Rectangle2D stringRect = g.getFontMetrics().getStringBounds(lineGroup.name, g);
            g.setColor(bg);
            drawInvertedString(g, lineGroup.name, xStart - stringRect.getWidth() - gap / 5, top + gap / 2 - stringRect.getCenterY());
        }
    }
// Rectangle2D rect = new Rectangle2D.Double()
}
Also used : Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 78 with Path2D

use of java.awt.geom.Path2D in project SimpleAsteroids by ljialin.

the class ArcPlot method paintComponent.

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(bg);
    g2.fillRect(0, 0, size.width, size.height);
    if (x == null)
        return;
    // ok, ready to go now
    // so what next?
    // step one, draw an arc
    // how thick?
    g2.translate(size.getWidth() / 2, size.getHeight() / 2);
    g2.setColor(fg);
    g2.setStroke(new BasicStroke(30));
    Path2D path = new Path2D.Double();
    Shape testArc = new Arc2D.Double(0, 0, 100, 100, 90, 180, Arc2D.OPEN);
    path.append(testArc, false);
    g2.draw(testArc);
}
Also used : Path2D(java.awt.geom.Path2D)

Example 79 with Path2D

use of java.awt.geom.Path2D in project SimpleAsteroids by ljialin.

the class View method drawShipPlayout.

private void drawShipPlayout(Graphics2D g, Ship ship, int[] seq) {
    g.setStroke(stroke);
    Path2D path = new Path2D.Double();
    path.moveTo(ship.s.x, ship.s.y);
    for (int a : seq) {
        // for (int i = 0; i< GameActionSpaceAdapterMulti.actionRepeat; i++) {
        // ship.update(SimpleBattleState.actions[a]);
        // }
        ship.update(actionAdapter.getAction(a));
        // the ship should be wrapped, but the problem is with how to draw the path
        // it would need to be restarted ...
        // gameState.forwardModel.wrap(ship);
        path.lineTo(ship.s.x, ship.s.y);
    }
    g.draw(path);
}
Also used : Path2D(java.awt.geom.Path2D)

Example 80 with Path2D

use of java.awt.geom.Path2D in project frostwire by frostwire.

the class SkinTabbedPaneTabBackgroundPainter method paintBorder.

private void paintBorder(Graphics2D g, int width, int height) {
    Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
    path.reset();
    int w = width - 4;
    int h = height - 1;
    path.moveTo(0, h);
    path.lineTo(0, 0);
    path.lineTo(w, 0);
    path.lineTo(w, h);
    path.lineTo(width, h);
    g.setPaint(SkinColors.GENERAL_BORDER_COLOR);
    g.draw(path);
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)126 Point2D (java.awt.geom.Point2D)20 Area (java.awt.geom.Area)16 Rectangle2D (java.awt.geom.Rectangle2D)13 Shape (java.awt.Shape)9 Point (java.awt.Point)8 Line2D (java.awt.geom.Line2D)8 PathIterator (java.awt.geom.PathIterator)8 ArrayList (java.util.ArrayList)8 AffineTransform (java.awt.geom.AffineTransform)7 GeneralPath (java.awt.geom.GeneralPath)7 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)6 Paint (java.awt.Paint)6 ShapeRoi (ij.gui.ShapeRoi)5 BasicStroke (java.awt.BasicStroke)4 RadialGradientPaint (java.awt.RadialGradientPaint)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Vector2D (de.gurkenlabs.litiengine.util.geom.Vector2D)2