private Point2D getPointFromSL(int saturation, int lightness, double radius) { double dy = map(saturation, 0, 255, -radius, radius); double angle = 0.; double angle1 = angle + 2 * Math.PI / 3.; double angle2 = angle1 + 2 * Math.PI / 3.; double x1 = radius * Math.sin(angle1); double y1 = radius * Math.cos(angle1); double x2 = radius * Math.sin(angle2); double y2 = radius * Math.cos(angle2); double dx = 0; double[] circle = circleFrom3Points(new Point2D(x1, y1), new Point2D(dx, dy), new Point2D(x2, y2)); double xArc = circle[0]; double yArc = circle[1]; double arcR = circle[2]; double Arco1 = Math.atan2(x1 - xArc, y1 - yArc); double Arco2 = Math.atan2(x2 - xArc, y2 - yArc); double ArcoFinal = map(lightness, 0, 255, Arco2, Arco1); double finalX = xArc + arcR * Math.sin(ArcoFinal); double finalY = yArc + arcR * Math.cos(ArcoFinal); if (dy < y1) { ArcoFinal = map(lightness, 0, 255, Arco1, Arco2 + 2 * Math.PI); finalX = -xArc - arcR * Math.sin(ArcoFinal); finalY = yArc + arcR * Math.cos(ArcoFinal); } return new Point2D(finalX, finalY); }
private Point2D scale(final Point2D a, final double scale) { return new Point2D(a.getX() * scale, a.getY() * scale); }
private Point2D makeControlPoint(final double endX, final double endY, final Circle circle, final int numSegments, int direction) { final double controlPointDistance = (4.0 / 3.0) * Math.tan(Math.PI / (2 * numSegments)) * circle.getRadius(); final Point2D center = new Point2D(circle.getCenterX(), circle.getCenterY()); final Point2D end = new Point2D(endX, endY); Point2D perp = rotate(center, end, direction * Math.PI / 2.); Point2D diff = perp.subtract(end); diff = diff.normalize(); diff = scale(diff, controlPointDistance); return end.add(diff); }
@Override protected void interpolate(double frac) { double dif = Math.min(Math.abs(toTheta - fromTheta), 2 * Math.PI - Math.abs(toTheta - fromTheta)); if (dif == 2 * Math.PI - Math.abs(toTheta - fromTheta)) { int dir = -1; if (toTheta < fromTheta) { dir = 1; } dif = dir * dif; } else { dif = toTheta - fromTheta; } Point2D newP = rotate(from, new Point2D(centerX, centerY), frac * dif); colorSelector.setRotate(90 + Math.toDegrees(Math.atan2(newP.getY() - centerY, newP.getX() - centerX))); colorSelector.setTranslateX(newP.getX() - colorSelector.getPrefWidth() / 2); colorSelector.setTranslateY(newP.getY() - colorSelector.getPrefHeight() / 2); } }
private Point2D rotate(final Point2D a, final Point2D center, final double angle) { final double resultX = center.getX() + (a.getX() - center.getX()) * Math.cos(angle) - (a.getY() - center.getY()) * Math .sin(angle); final double resultY = center.getY() + (a.getX() - center.getX()) * Math.sin(angle) + (a.getY() - center.getY()) * Math .cos(angle); return new Point2D(resultX, resultY); }
private Point2D rotate(Point2D a, Point2D center, double angle) { double resultX = center.getX() + (a.getX() - center.getX()) * Math.cos(angle) - (a.getY() - center.getY()) * Math .sin(angle); double resultY = center.getY() + (a.getX() - center.getX()) * Math.sin(angle) + (a.getY() - center.getY()) * Math .cos(angle); return new Point2D(resultX, resultY); }
private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dx = x - center.getX(); double dy = y - center.getY(); double distance = Math.sqrt((dx * dx) + (dy * dy)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
private Image getSLCricle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dy = x - center.getX(); double dx = y - center.getY(); pixelWriter.setColor(x, y, getColor(dx, dy)); } } return raster; }
> var p = new Point2D(99, 123) undefined > p.x 99 > p.x = 7 7 > p.x 99 > p.foo = "This won't be added" undefined > JSON.stringify(p); "{"x":99,"y":123}"
double x = centerX + huesRadius * Math.cos(theta); double y = centerY + huesRadius * Math.sin(theta); colorsTransition = new CurveTransition(new Point2D(colorSelector.getTranslateX() + colorSelector.getPrefWidth() / 2, colorSelector.getTranslateY() + colorSelector.getPrefHeight() / 2), new Point2D(x, y));
double x = centerX + huesRadius * Math.cos(theta); double y = centerY + huesRadius * Math.sin(theta); colorsTransition = new CurveTransition(new Point2D(colorSelector.getTranslateX() + colorSelector.getPrefWidth() / 2, colorSelector.getTranslateY() + colorSelector.getPrefHeight() / 2), new Point2D(x, y)); colorsTransition.play(); });
private Point2D getDisplayCoordiantes(Window owner, Scene scene) { Point2D nodeCoord = ValidableTextField.this.localToScene(0.0, ValidableTextField.this.getHeight()); double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2); double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() - 2); return new Point2D(anchorX, anchorY); } }
@Override protected Point2D getInitialSize(Parent rootContainer) { return new Point2D(400, 400); } };
/** * Initializes the right triangle who's hypotenuse is facing north-east. */ private void initTriangleNorthEast() { this.addPolygonPoints( new Point2D(0d, 0d), // top new Point2D(side2Length, side1Length), new Point2D(0d, side1Length) ); this.layoutTriangle((side2Length / 3d), (2d * side1Length / 3d)); } // END initTriangleNorthEast
private List<Point2D> convertToPoints(ObservableList<Double> points) { ArrayList<Point2D> list = new ArrayList<>(); for (Iterator<Double> it = points.iterator(); it.hasNext();) { double x = it.next(); double y = it.next(); list.add(new Point2D(x, y)); } return list; }
node.setOnMouseDragged(new EventHandler<MouseEvent>() { public void handle(MouseEvent e) { Point2D localPoint = sceneRoot.sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY())); dragImageView.relocate( (int)(localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
private Point2D getLocationCoordinates(WorldMapView.Location location) { double x = (location.getLongitude() + 180) * (PREFERRED_WIDTH / 360) + MAP_OFFSET_X; double y = (PREFERRED_HEIGHT / 2) - (PREFERRED_WIDTH * (Math.log(Math.tan((Math.PI / 4) + (Math.toRadians(location.getLatitude()) / 2)))) / (2 * Math.PI)) + MAP_OFFSET_Y; return new Point2D(x, y); }
private List<Point2D> applyScale(List<Point2D> pointedPath, double scale) { ArrayList<Point2D> list = new ArrayList<>(); for (Point2D p : pointedPath) { list.add(new Point2D(p.getX()*scale, p.getY()*scale)); } return list; }
@Override public Point2D center() { Bounds bounds = node.localToScreen(node.getBoundsInLocal()); return new Point2D(bounds.getMinX() + bounds.getWidth()/2, bounds.getMinY() + bounds.getHeight()/2); }