private static Path processPath(final List<String> PATH_LIST, final PathReader READER) { final Path PATH = new Path(); PATH.setFillRule(FillRule.EVEN_ODD); while (!PATH_LIST.isEmpty()) { if ("M".equals(READER.read())) { PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY())); } else if ("C".equals(READER.read())) { PATH.getElements().add(new CubicCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("Q".equals(READER.read())) { PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("H".equals(READER.read())) { PATH.getElements().add(new HLineTo(READER.nextX())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new VLineTo(READER.nextY())); } else if ("A".equals(READER.read())) { PATH.getElements().add(new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false)); } else if ("Z".equals(READER.read())) { PATH.getElements().add(new ClosePath()); } } return PATH; }
public PathSample() { super(180,90); // Create path shape - square Path path1 = new Path(); path1.getElements().addAll( new MoveTo(25, 25), new HLineTo(65), new VLineTo(65), new LineTo(25, 65), new ClosePath() ); path1.setFill(null); path1.setStroke(Color.RED); path1.setStrokeWidth(2); // Create path shape - curves Path path2 = new Path(); path2.getElements().addAll( new MoveTo(100, 45), new CubicCurveTo(120, 20, 130, 80, 140, 45), new QuadCurveTo(150, 0, 160, 45), new ArcTo(20, 40, 0, 180, 45, true, true) ); path2.setFill(null); path2.setStroke(Color.DODGERBLUE); path2.setStrokeWidth(2); // show the path shapes; getChildren().add(new Group(path1, path2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()), new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty()) ); // END REMOVE ME }
/** * Create a transition * * @param sourceElements * the source elements * @param targetElements * the target elements * @param duation * the duration * @param pathNode * the path not the morph is done on */ public PathMorphTransition(List<PathElement> sourceElements, List<PathElement> targetElements, Duration duation, Path pathNode) { this.pathNode = pathNode; setCycleDuration(duation); if (sourceElements.size() != targetElements.size()) { throw new IllegalArgumentException("Only equal paths are allowed"); //$NON-NLS-1$ } for (int i = 0; i < sourceElements.size(); i++) { PathElement sourceElement = sourceElements.get(i); PathElement targetElement = targetElements.get(i); if (sourceElement.getClass() != targetElement.getClass()) { throw new IllegalArgumentException("Only equal paths are allowed"); //$NON-NLS-1$ } if (sourceElement instanceof ArcTo) { this.interpolateList.add(new ArcToInterpolatable((ArcTo) sourceElement)); } else if (sourceElement instanceof CubicCurveTo) { this.interpolateList.add(new CubicCurveToInterpolatable((CubicCurveTo) sourceElement)); } else if (sourceElement instanceof HLineTo) { this.interpolateList.add(new HLineToInterpolatable((HLineTo) sourceElement)); } else if (sourceElement instanceof LineTo) { this.interpolateList.add(new LineToInterpolatable((LineTo) sourceElement)); } else if (sourceElement instanceof MoveTo) { this.interpolateList.add(new MoveToInterpolatable((MoveTo) sourceElement)); } else if (sourceElement instanceof QuadCurveTo) { this.interpolateList.add(new QuadCurveToInterpolatable((QuadCurveTo) sourceElement)); } else if (sourceElement instanceof VLineTo) { this.interpolateList.add(new VLineToInterpolatable((VLineTo) sourceElement)); } } this.sourceElements = sourceElements; this.targetElements = targetElements; }
@Override public QuadCurveTo interpolate(QuadCurveTo endValue, double t) { QuadCurveTo rv = new QuadCurveTo(this.source.getControlX() + (endValue.getControlX() - this.source.getControlX()) * t, this.source.getControlY() + (endValue.getControlY() - this.source.getControlY()) * t, this.source.getX() + (endValue.getX() - this.source.getX()) * t, this.source.getY() + (endValue.getY() - this.source.getY()) * t); rv.setAbsolute(this.source.isAbsolute()); return rv; }
public static void setPath(Path p, Path2D p2d) { p.getElements().clear(); PathIterator pi = p2d.getPathIterator(null); double[] coords = new double[6]; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: p.getElements().add(new MoveTo(coords[0], coords[1])); break; case PathIterator.SEG_LINETO: p.getElements().add(new LineTo(coords[0], coords[1])); break; case PathIterator.SEG_QUADTO: p.getElements().add(new QuadCurveTo(coords[0], coords[1], coords[2], coords[3])); break; case PathIterator.SEG_CUBICTO: p.getElements().add(new CubicCurveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5])); break; case PathIterator.SEG_CLOSE: p.getElements().add(new ClosePath()); break; default: throw new InternalError("unexpected segment type"); } pi.next(); } p.getElements().add(new ClosePath()); }
private Point3D evalQuadBezier(QuadCurveTo c, Point3D ini, double t){ Point3D p=new Point3D((float)(Math.pow(1-t,2)*ini.x+ 2*(1-t)*t*c.getControlX()+ Math.pow(t, 2)*c.getX()), (float)(Math.pow(1-t,2)*ini.y+ 2*(1-t)*t*c.getControlY()+ Math.pow(t, 2)*c.getY()), 0f); return p; }
private static Path processPath(final List<String> PATH_LIST, final PathReader READER) { final Path PATH = new Path(); PATH.setFillRule(FillRule.EVEN_ODD); while (!PATH_LIST.isEmpty()) { if ("M".equals(READER.read())) { PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY())); } else if ("C".equals(READER.read())) { PATH.getElements().add(new CubicCurveTo( READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("Q".equals(READER.read())) { PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("H".equals(READER.read())) { PATH.getElements().add(new HLineTo(READER.nextX())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new VLineTo(READER.nextY())); } else if ("A".equals(READER.read())) { PATH.getElements().add( new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false)); } else if ("Z".equals(READER.read())) { PATH.getElements().add(new ClosePath()); } } return PATH; }
public static String convertPath(final Path PATH) { final StringBuilder fxPath = new StringBuilder(); for (PathElement element : PATH.getElements()) { if (MoveTo.class.equals(element.getClass())) { fxPath.append("M ") .append(((MoveTo) element).getX()).append(" ") .append(((MoveTo) element).getY()).append(" "); } else if (LineTo.class.equals(element.getClass())) { fxPath.append("L ") .append(((LineTo) element).getX()).append(" ") .append(((LineTo) element).getY()).append(" "); } else if (CubicCurveTo.class.equals(element.getClass())) { fxPath.append("C ") .append(((CubicCurveTo) element).getControlX1()).append(" ") .append(((CubicCurveTo) element).getControlY1()).append(" ") .append(((CubicCurveTo) element).getControlX2()).append(" ") .append(((CubicCurveTo) element).getControlY2()).append(" ") .append(((CubicCurveTo) element).getX()).append(" ") .append(((CubicCurveTo) element).getY()).append(" "); } else if (QuadCurveTo.class.equals(element.getClass())) { fxPath.append("Q ") .append(((QuadCurveTo) element).getControlX()).append(" ") .append(((QuadCurveTo) element).getControlY()).append(" ") .append(((QuadCurveTo) element).getX()).append(" ") .append(((QuadCurveTo) element).getY()).append(" "); } else if (ArcTo.class.equals(element.getClass())) { fxPath.append("A ") .append(((ArcTo) element).getX()).append(" ") .append(((ArcTo) element).getY()).append(" ") .append(((ArcTo) element).getRadiusX()).append(" ") .append(((ArcTo) element).getRadiusY()).append(" "); } else if (HLineTo.class.equals(element.getClass())) { fxPath.append("H ") .append(((HLineTo) element).getX()).append(" "); } else if (VLineTo.class.equals(element.getClass())) { fxPath.append("V ") .append(((VLineTo) element).getY()).append(" "); } else if (ClosePath.class.equals(element.getClass())) { fxPath.append("Z"); } } return fxPath.toString(); }
public static String convertPath(final Path PATH) { final StringBuilder fxPath = new StringBuilder(); for (PathElement element : PATH.getElements()) { if (MoveTo.class.equals(element.getClass())) { fxPath .append("M ") .append(((MoveTo) element).getX()) .append(" ") .append(((MoveTo) element).getY()) .append(" "); } else if (LineTo.class.equals(element.getClass())) { fxPath .append("L ") .append(((LineTo) element).getX()) .append(" ") .append(((LineTo) element).getY()) .append(" "); } else if (CubicCurveTo.class.equals(element.getClass())) { fxPath .append("C ") .append(((CubicCurveTo) element).getControlX1()) .append(" ") .append(((CubicCurveTo) element).getControlY1()) .append(" ") .append(((CubicCurveTo) element).getControlX2()) .append(" ") .append(((CubicCurveTo) element).getControlY2()) .append(" ") .append(((CubicCurveTo) element).getX()) .append(" ") .append(((CubicCurveTo) element).getY()) .append(" "); } else if (QuadCurveTo.class.equals(element.getClass())) { fxPath .append("Q ") .append(((QuadCurveTo) element).getControlX()) .append(" ") .append(((QuadCurveTo) element).getControlY()) .append(" ") .append(((QuadCurveTo) element).getX()) .append(" ") .append(((QuadCurveTo) element).getY()) .append(" "); } else if (ArcTo.class.equals(element.getClass())) { fxPath .append("A ") .append(((ArcTo) element).getX()) .append(" ") .append(((ArcTo) element).getY()) .append(" ") .append(((ArcTo) element).getRadiusX()) .append(" ") .append(((ArcTo) element).getRadiusY()) .append(" "); } else if (HLineTo.class.equals(element.getClass())) { fxPath.append("H ").append(((HLineTo) element).getX()).append(" "); } else if (VLineTo.class.equals(element.getClass())) { fxPath.append("V ").append(((VLineTo) element).getY()).append(" "); } else if (ClosePath.class.equals(element.getClass())) { fxPath.append("Z"); } } return fxPath.toString(); }
public QuadCurveToInterpolatable(QuadCurveTo source) { this.source = source; }