Search in sources :

Example 56 with Polygon

use of java.awt.Polygon in project freeplane by freeplane.

the class DrawableRectangle method getShape.

Shape getShape(Rectangle r) {
    final Polygon polygon = new Polygon();
    final int x1 = r.x + 1;
    final int x2 = x1 + r.width - 3;
    final int y1 = r.y + 1;
    final int y2 = y1 + r.height - 3;
    polygon.addPoint(x1, y1);
    polygon.addPoint(x2, y1);
    polygon.addPoint(x2, y2);
    polygon.addPoint(x1, y2);
    polygon.addPoint(x1, y1);
    return polygon;
}
Also used : Polygon(java.awt.Polygon)

Example 57 with Polygon

use of java.awt.Polygon in project freeplane by freeplane.

the class VariableInsetsMainView method polygonOf.

protected Polygon polygonOf(double[] xCoords, double[] yCoords) {
    int edgeWidthOffset = (int) getPaintedBorderWidth();
    final Polygon polygon = new Polygon(toInt(xCoords, edgeWidthOffset / 2, getWidth() - edgeWidthOffset), toInt(yCoords, edgeWidthOffset / 2, getHeight() - edgeWidthOffset), xCoords.length);
    return polygon;
}
Also used : Polygon(java.awt.Polygon)

Example 58 with Polygon

use of java.awt.Polygon in project freeplane by freeplane.

the class AConnectorView method paintArrow.

/**
 * @param from
 *            is the another point indicating the direction of the arrow.
 * @param to
 *            is the start point
 * @param d
 */
protected void paintArrow(final Point from, final Point to, final Graphics2D g, final double size) {
    int dx, dy;
    double dxn, dyn;
    dx = from.x - to.x;
    dy = from.y - to.y;
    final int r2 = dx * dx + dy * dy;
    if (r2 == 0)
        return;
    final double length = Math.sqrt(r2);
    dxn = size * dx / length;
    dyn = size * dy / length;
    final double arrowWidth = .5f;
    final Polygon p = new Polygon();
    p.addPoint((to.x), (to.y));
    p.addPoint((int) (to.x + dxn + arrowWidth * dyn), (int) (to.y + dyn - arrowWidth * dxn));
    p.addPoint((int) (to.x + dxn - arrowWidth * dyn), (int) (to.y + dyn + arrowWidth * dxn));
    p.addPoint((to.x), (to.y));
    g.fillPolygon(p);
    g.drawPolygon(p);
}
Also used : Polygon(java.awt.Polygon) Point(java.awt.Point)

Example 59 with Polygon

use of java.awt.Polygon in project freeplane by freeplane.

the class StarCloudView method paintDecoration.

protected void paintDecoration(final Graphics2D g, final Graphics2D gstroke, final double x0, final double y0, final double x1, final double y1, double dx, double dy, double dxn, double dyn) {
    final double xctrl, yctrl;
    final double middleDistanceToConvexHull = getDistanceToConvexHull();
    final double distanceToConvexHull = middleDistanceToConvexHull * random(0.5);
    final double k = random(0.3);
    xctrl = x0 + .5f * dx * k - distanceToConvexHull * dyn;
    yctrl = y0 + .5f * dy * k + distanceToConvexHull * dxn;
    final Polygon shape = new Polygon();
    shape.addPoint((int) x0, (int) y0);
    shape.addPoint((int) xctrl, (int) yctrl);
    shape.addPoint((int) x1, (int) y1);
    g.fill(shape);
    gstroke.drawLine((int) x0, (int) y0, (int) xctrl, (int) yctrl);
    gstroke.drawLine((int) xctrl, (int) yctrl, (int) x1, (int) y1);
}
Also used : Polygon(java.awt.Polygon)

Example 60 with Polygon

use of java.awt.Polygon in project chordatlas by twak.

the class SuperMeshPainter method paint.

@Override
public void paint(Object oa, Graphics2D g2, PanMouseAdaptor ma) {
    HalfMesh2 o = (HalfMesh2) oa;
    double scatterRadius = 0.0;
    if (o.faces.isEmpty())
        return;
    double maxHeight = o.faces.stream().mapToDouble(x -> ((SuperFace) x).height).max().getAsDouble();
    // (int) ( Math.random() * 100 );
    int fc = 0;
    for (HalfFace f : o.faces) {
        fc++;
        Polygon pwt = new Polygon();
        try {
            for (HalfEdge e : f.edges()) {
                pwt.addPoint(ma.toX(e.start.x + Math.random() * scatterRadius), ma.toY(e.start.y + Math.random() * scatterRadius));
            // PaintThing.paint(e.start, g2, ma);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
        SuperFace sf = (SuperFace) f;
        Color c;
        if (false) {
            int h = (int) Mathz.clamp(((SuperFace) f).height * 5, 0, 255);
            if (((SuperFace) f).height == -Double.MAX_VALUE)
                c = Color.green;
            else if (((SuperFace) f).height < 0)
                c = Color.red;
            else
                c = new Color(h, h, h);
        } else if (sf.height == -Double.MAX_VALUE) {
            c = Color.yellow;
        } else if (sf.classification == -1 || sf.height < 0) {
            c = Color.red;
        } else {
            // c = Color.white;
            c = Rainbow.getColour(sf.classification + 1);
        // c = Rainbow.getColour( fc++ + 1 );
        }
        // c = Color.white;
        // new Color( c.getRed(), c.getGreen(), c.getBlue(), 50 ) );
        g2.setColor(c);
        g2.fill(pwt);
    // Loop<Point2d> pts = new Loop<>();
    // for ( HalfEdge e : f.edges() )
    // pts.append(e.end);
    // 
    // if ( ( Loopz.area( pts ) ) < 0.1 ) {
    // g2.setColor(Color.red);
    // g2.setStroke( new BasicStroke( 4f ) );
    // g2.draw( pwt );
    // }
    }
    for (HalfFace f : o.faces) {
        g2.setColor(Color.black);
        try {
            for (HalfEdge e : f) {
                SuperEdge se = (SuperEdge) e;
                g2.setColor(Color.black);
                if (se.proceduralFacade != null) {
                    g2.setStroke(new BasicStroke(3f));
                } else {
                    g2.setStroke(new BasicStroke(1f));
                }
            // if ( se.profLine != null || ( se.over != null && ((SuperEdge)se.over).profLine != null ) ) {
            // g2.setStroke( new BasicStroke( 2f ) );
            // g2.setColor( new Color (255, 0, 0 ) );
            // }
            // else
            // {
            // g2.setStroke( new BasicStroke( 1f ) );
            // g2.setColor( Color.black );
            // }
            // g2.setColor( ((SuperEdge)e).profLine == null? Color.green : Color.magenta);
            // PaintThing.paint ( e.line(), g2, ma );
            // }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        g2.setStroke(new BasicStroke(3));
        if (false)
            for (HalfEdge e : f.edges()) {
                SuperEdge se = (SuperEdge) e;
                if (se.profLine != null) {
                    // g2.setColor( Color.BLACK );
                    // new Line (new Point2d (e.start), new Point2d (e.end));
                    Line l = se.line();
                    // PaintThing.drawArrow( g2, ma, l, 5 );
                    g2.drawLine(ma.toX(l.start.x), ma.toY(l.start.y), ma.toX(l.end.x), ma.toY(l.end.y));
                }
            // if (e.over != null)
            // {
            // l.moveLeft( ma.fromZoom( 2 ) );
            // 
            // double delta = Math.abs (  ((SuperEdge)e).localHeight - ((SuperEdge)e.over).localHeight );
            // 
            // int h =  (int) Math.min(255, delta * 10 ) ;
            // g2.setColor ( new Color (0,h,h) );
            // g2.setStroke (new BasicStroke( 3f ));
            // 
            // }
            // if ( ( (SuperEdge) e ).debug ) {
            // if ( e.over == null || ((SuperFace)e.over.face).classification != ((SuperFace)f).classification ) {
            // g2.setColor( Color.black );
            // g2.setStroke( new BasicStroke( 2 ) );
            // PaintThing.paint( e.line(), g2, ma );
            // }
            }
    }
    fc = 0;
    if (false)
        for (HalfFace f : o.faces) {
            for (HalfEdge e : f.edges()) {
                // Point2d pt = new Point2d(e.start);
                // pt.add( off );
                // Point2d pt2 = new Point2d(e.end);
                // pt2.add( off );
                // 
                // PaintThing.paint( new Line (pt, pt2) , g2, ma );
                g2.setColor(new Color(255, 0, 0, 20));
                if (e.line().absAngle(e.next.line()) > Math.PI - 0.001) {
                    g2.setColor(new Color(0, 255, 0, 255));
                }
                PaintThing.paint(new Line(e.start, e.end), g2, ma);
                PaintThing.paint(new Line(e.next.start, e.next.end), g2, ma);
            }
        // for ( HalfEdge e : f.edges() ) {
        // PaintThing.drawArrow( g2, ma, e.line(), 5 );
        // }
        }
    if (false)
        for (HalfFace f : o.faces) for (HalfEdge e : f.edges()) {
            if (e.face != f || (e.over != null && (e.over.over != e || !o.faces.contains(e.over.face))) || e.face == null || e.start == null || e.end == null || e.next == null) {
                g2.setColor(Color.red);
                g2.setStroke(new BasicStroke(4));
                PaintThing.paint(e.line(), g2, ma);
            }
        }
}
Also used : BasicStroke(java.awt.BasicStroke) Line(org.twak.utils.Line) Color(java.awt.Color) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Polygon(java.awt.Polygon) SuperFace(org.twak.tweed.gen.SuperFace) SuperEdge(org.twak.tweed.gen.SuperEdge) HalfMesh2(org.twak.utils.geom.HalfMesh2)

Aggregations

Polygon (java.awt.Polygon)192 Point (java.awt.Point)53 Rectangle (java.awt.Rectangle)30 Graphics2D (java.awt.Graphics2D)28 Area (java.awt.geom.Area)22 ArrayList (java.util.ArrayList)21 BasicStroke (java.awt.BasicStroke)20 Color (java.awt.Color)19 Paint (java.awt.Paint)15 Point2D (java.awt.geom.Point2D)13 AffineTransform (java.awt.geom.AffineTransform)12 Rectangle2D (java.awt.geom.Rectangle2D)12 Shape (java.awt.Shape)11 LocalPoint (net.runelite.api.coords.LocalPoint)11 Point (net.runelite.api.Point)10 FloatPolygon (ij.process.FloatPolygon)9 Font (java.awt.Font)8 List (java.util.List)8 FontMetrics (java.awt.FontMetrics)7 Stroke (java.awt.Stroke)7