本文整理汇总了Java中java.awt.geom.Path2D.closePath方法的典型用法代码示例。如果您正苦于以下问题:Java Path2D.closePath方法的具体用法?Java Path2D.closePath怎么用?Java Path2D.closePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Path2D
的用法示例。
在下文中一共展示了Path2D.closePath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeEllipse
import java.awt.geom.Path2D; //导入方法依赖的package包/类
public Path2D makeEllipse(Complex G1, Complex G2, int m, double xOffset, double yOffset) {
Path2D path = new Path2D.Float();
int recPoints = Math.max(minReconstructionSamples, G.length * 3);
for (int i = 0; i < recPoints; i++) {
double t = (double) i / recPoints;
Complex p1 = this.getEllipsePoint(G1, G2, m, t);
double xt = p1.re();
double yt = p1.im();
if (i == 0) {
path.moveTo(xt + xOffset, yt + yOffset);
}
else {
path.lineTo(xt + xOffset, yt + yOffset);
}
}
path.closePath();
return path;
}
示例2: drawArrow
import java.awt.geom.Path2D; //导入方法依赖的package包/类
private Path2D drawArrow(int x1, int y1, int x2, int y2) {
Path2D context = new Path2D.Float();
int headlen = 10; // length of head in pixels
double angle = Math.atan2(y2 - y1, x2 - x1);
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.lineTo(x2 - headlen * Math.cos(angle - Math.PI / 6), y2 - headlen * Math.sin(angle - Math.PI / 6));
context.moveTo(x2, y2);
context.lineTo(x2 - headlen * Math.cos(angle + Math.PI / 6), y2 - headlen * Math.sin(angle + Math.PI / 6));
context.closePath();
return context;
}
示例3: makePolygon
import java.awt.geom.Path2D; //导入方法依赖的package包/类
@Deprecated
public static Roi makePolygon(Point2D[] points, double strokeWidth, Color color) {
Path2D poly = new Path2D.Double();
if (points.length > 0) {
poly.moveTo(points[0].getX(), points[0].getY());
for (int i = 1; i < points.length; i++) {
poly.lineTo(points[i].getX(), points[i].getY());
}
poly.closePath();
}
Roi shapeRoi = new ShapeRoi(poly);
shapeRoi.setStrokeWidth(strokeWidth);
shapeRoi.setStrokeColor(color);
return shapeRoi;
}
示例4: makeFourierPairsReconstruction
import java.awt.geom.Path2D; //导入方法依赖的package包/类
/**
* Reconstructs the shape obtained from FD-pairs 0,...,Mp as a polygon (path).
*
* @param Mp number of Fourier coefficient pairs
* @return reconstructed shape
*/
public Path2D makeFourierPairsReconstruction(int Mp) {
int M = G.length;
Mp = Math.min(Mp, M/2);
int recPoints = Math.max(minReconstructionSamples, G.length * 3);
Path2D path = new Path2D.Float();
for (int i = 0; i < recPoints; i++) {
double t = (double) i / recPoints;
Complex pt = new Complex(getCoefficient(0)); // assumes that coefficient 0 is never scaled
// calculate a particular reconstruction point
for (int m = 1; m <= Mp; m++) {
Complex ep = getEllipsePoint(getCoefficient(-m), getCoefficient(m), m, t);
pt = pt.add(ep.mult(reconstructionScale));
}
double xt = pt.re();
double yt = pt.im();
if (i == 0) {
path.moveTo(xt, yt);
}
else {
path.lineTo(xt, yt);
}
}
path.closePath();
return path;
}
示例5: renderLightSource
import java.awt.geom.Path2D; //导入方法依赖的package包/类
private void renderLightSource(final Graphics2D g, final LightSource light, final double longerDimension) {
final Point2D lightCenter = light.getDimensionCenter();
final Area lightArea = new Area(light.getLightShape());
if (light.getLightShapeType().equals(LightSource.RECTANGLE)) {
g.setColor(light.getColor());
g.fill(lightArea);
return;
}
// cut the light area where shadow Boxes are (this simulates light falling
// into and out of rooms)
for (final StaticShadow col : this.environment.getStaticShadows()) {
if (!GeometricUtilities.shapeIntersects(light.getLightShape(), col.getBoundingBox())) {
continue;
}
final Area boxInLight = new Area(col.getBoundingBox());
boxInLight.intersect(lightArea);
final Line2D[] bounds = GeometricUtilities.getLines(col.getBoundingBox());
for (final Line2D line : bounds) {
final Vector2D lineVector = new Vector2D(line.getP1(), line.getP2());
final Vector2D lightVector = new Vector2D(lightCenter, line.getP1());
if (light.getDimensionCenter().getY() < line.getY1() && light.getDimensionCenter().getY() < line.getY2() && col.getBoundingBox().contains(light.getDimensionCenter()) || lineVector.normalVector().dotProduct(lightVector) >= 0) {
continue;
}
final Path2D shadowParallelogram = new Path2D.Double();
final Point2D shadowPoint1 = GeometricUtilities.project(lightCenter, line.getP1(), longerDimension);
final Point2D shadowPoint2 = GeometricUtilities.project(lightCenter, line.getP2(), longerDimension);
// construct a shape from our points
shadowParallelogram.moveTo(line.getP1().getX(), line.getP1().getY());
shadowParallelogram.lineTo(shadowPoint1.getX(), shadowPoint1.getY());
shadowParallelogram.lineTo(shadowPoint2.getX(), shadowPoint2.getY());
shadowParallelogram.lineTo(line.getP2().getX(), line.getP2().getY());
shadowParallelogram.closePath();
final Area shadowArea = new Area(shadowParallelogram);
if (light.getDimensionCenter().getY() < col.getBoundingBox().getMaxY() && !col.getBoundingBox().contains(light.getDimensionCenter())) {
shadowArea.add(boxInLight);
}
shadowArea.intersect(lightArea);
lightArea.subtract(shadowArea);
}
}
final Paint oldPaint = g.getPaint();
// render parts that lie within the shadow with a gradient from the light
// color to transparent
final Area lightRadiusArea = new Area(light.getLightShape());
final Color[] transColors = new Color[] { new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), light.getBrightness()), new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), 0) };
try {
g.setPaint(new RadialGradientPaint(new Point2D.Double(lightRadiusArea.getBounds2D().getCenterX(), lightRadiusArea.getBounds2D().getCenterY()), (float) (lightRadiusArea.getBounds2D().getWidth() / 2), new float[] { 0.0f, 1.00f }, transColors));
} catch (final Exception e) {
g.setColor(light.getColor());
}
g.fill(lightArea);
g.setPaint(oldPaint);
}
示例6: getShape
import java.awt.geom.Path2D; //导入方法依赖的package包/类
@Override
public Shape getShape() {
Path2D shape = new Path2D.Float();
int xDiff = Math.abs(getSuperclass().getCenterX() - getSubclass().getCenterX());
int yDiff = Math.abs(getSuperclass().getCenterY() - getSubclass().getCenterY());
if (xDiff > 2 * yDiff) {
if (getSuperclass().getStartX() > getSubclass().getEndX()) {
trianglePosition = Position.LEFT;
shape.moveTo(getSuperclass().getStartX(), getSuperclass().getCenterY());
shape.lineTo(getSuperclass().getStartX() - cos30,
getSuperclass().getCenterY() - sin30);
shape.lineTo(getSuperclass().getStartX() - cos30,
getSuperclass().getCenterY() - sinNeg30);
shape.lineTo(getSuperclass().getStartX(), getSuperclass().getCenterY());
} else if (getSuperclass().getEndX() < getSubclass().getStartX()) {
trianglePosition = Position.RIGHT;
shape.moveTo(getSuperclass().getEndX(), getSuperclass().getCenterY());
shape.lineTo(getSuperclass().getEndX() + cos30,
getSuperclass().getCenterY() + sin30);
shape.lineTo(getSuperclass().getEndX() + cos30,
getSuperclass().getCenterY() + sinNeg30);
shape.lineTo(getSuperclass().getEndX(), getSuperclass().getCenterY());
}
} else {
if (getSuperclass().getStartY() > getSubclass().getEndY()) {
trianglePosition = Position.TOP;
shape.moveTo(getSuperclass().getCenterX(), getSuperclass().getStartY());
shape.lineTo(getSuperclass().getCenterX() - sin30,
getSuperclass().getStartY() - cos30);// 30°
shape.lineTo(getSuperclass().getCenterX() - sinNeg30,
getSuperclass().getStartY() - cosNeg30);// 30°
shape.lineTo(getSuperclass().getCenterX(), getSuperclass().getStartY());
} else {
trianglePosition = Position.BOTTOM;
shape.moveTo(getSuperclass().getCenterX(), getSuperclass().getEndY());
shape.lineTo(getSuperclass().getCenterX() + sin30,
getSuperclass().getEndY() + cos30);// 30°
shape.lineTo(getSuperclass().getCenterX() + sinNeg30,
getSuperclass().getEndY() + cosNeg30);// 30°
shape.lineTo(getSuperclass().getCenterX(), getSuperclass().getEndY());
}
}
try {
shape.closePath();
} catch (IllegalPathStateException e) {
return super.getShape();
}
shape.append(super.getShape(), false);
return shape;
}
示例7: addClose
import java.awt.geom.Path2D; //导入方法依赖的package包/类
static Path2D addClose(Path2D p2d) {
p2d.closePath();
return p2d;
}
示例8: addClose
import java.awt.geom.Path2D; //导入方法依赖的package包/类
static void addClose(Path2D p2d) {
p2d.closePath();
}
示例9: draw
import java.awt.geom.Path2D; //导入方法依赖的package包/类
@Override
public void draw(Graphics2D g) {
float wrap = (float)map.getWrap();
//get the limits of the displayed map
Rectangle2D rect = map.getClipRect2D();
double xmin = rect.getMinX();
double xmax = rect.getMaxX();
Projection proj = map.getProjection();
Point2D.Double pt = new Point2D.Double();
pt.x = getStartLon();
pt.y = getStartLat();
Point2D.Double p_start = (Point2D.Double) proj.getMapXY(pt);
if( wrap>0f ) {
while( p_start.x <= xmin ){p_start.x+=wrap;}
while( p_start.x >= xmax ){p_start.x-=wrap;}
}
pt.x = getEndLon();
pt.y = getEndLat();
Point2D.Double p_end = (Point2D.Double) proj.getMapXY(pt);
if( wrap>0f ) {
while( p_end.x <= xmin ){p_end.x+=wrap;}
while( p_end.x > wrap + xmin ){p_end.x-=wrap;}
}
//draw the shortest line - either p_start.x to p_end.x or the x+wrap values.
if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) >
((p_start.x - (p_end.x + wrap)) * (p_start.x - (p_end.x + wrap))) ) {p_end.x += wrap;}
if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) >
(((p_start.x + wrap) - p_end.x) * ((p_start.x + wrap) - p_end.x)) ) {p_start.x += wrap;}
if (lineNum == 1) g.setColor( Color.RED );
else g.setColor( Color.black );
double zoom = map.getZoom();
g.setStroke( new BasicStroke( 2f/(float)zoom ));
double arr_size = 6./zoom;
double sq_size = 6./zoom;
double dx = p_end.x - p_start.x, dy = p_end.y - p_start.y;
double angle = Math.atan2(dy, dx);
double len = Math.sqrt(dx*dx + dy*dy);
AffineTransform at = g.getTransform();
g.translate(p_start.x, p_start.y);
g.rotate(angle);
//draw the line
g.draw(new Line2D.Double(0, 0, len, 0));
//draw the arrow
Path2D arrow = new Path2D.Double();
double xpts[] = {len/3d, len/3d-arr_size, len/3d-arr_size, len/3d};
double ypts[] = {0, -arr_size, arr_size, 0};
arrow.moveTo(xpts[0], ypts[0]);
arrow.lineTo(xpts[1], ypts[1]);
arrow.lineTo(xpts[2], ypts[2]);
arrow.closePath();
if (lineNum == 1) g.setColor( Color.ORANGE );
else g.setColor( Color.ORANGE );
g.fill(arrow);
if (lineNum == 1) g.setColor( Color.RED );
else g.setColor( Color.black );
//draw squares at the end points
Rectangle2D startSq = new Rectangle2D.Double(0d-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
Rectangle2D endSq = new Rectangle2D.Double(len-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
g.fill(startSq);
g.fill(endSq);
g.setTransform(at);
}