Search in sources :

Example 26 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 27 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 28 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 29 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)

Aggregations

Path2D (java.awt.geom.Path2D)29 Rectangle2D (java.awt.geom.Rectangle2D)5 Graphics2D (java.awt.Graphics2D)4 BasicStroke (java.awt.BasicStroke)3 PathIterator (java.awt.geom.PathIterator)3 TDoubleArrayList (gnu.trove.TDoubleArrayList)2 Color (java.awt.Color)2 Font (java.awt.Font)2 AffineTransform (java.awt.geom.AffineTransform)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 Point2D (aima.core.util.math.geom.shapes.Point2D)1 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)1 SeriesData (com.android.tools.adtui.model.SeriesData)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Insets (java.awt.Insets)1 Paint (java.awt.Paint)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1