Search in sources :

Example 16 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method moveToColor.

public void moveToColor(Color color) {
    allowColorChange = false;
    double max = Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue())), min = Math.min(color.getRed(), Math.min(color.getGreen(), color.getBlue()));
    double hue = 0;
    double l = (max + min) / 2;
    double s = 0;
    if (max == min) {
        // achromatic
        hue = s = 0;
    } else {
        double d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        if (max == color.getRed()) {
            hue = (color.getGreen() - color.getBlue()) / d + (color.getGreen() < color.getBlue() ? 6 : 0);
        } else if (max == color.getGreen()) {
            hue = (color.getBlue() - color.getRed()) / d + 2;
        } else if (max == color.getBlue()) {
            hue = (color.getRed() - color.getGreen()) / d + 4;
        }
        hue /= 6;
    }
    currentHue = map(hue, 0, 1, 0, 255);
    // Animate Hue
    double theta = map(currentHue, 0, 255, -Math.PI, Math.PI);
    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));
    // Animate SL
    s = map(s, 0, 1, 0, 255);
    l = map(l, 0, 1, 0, 255);
    Point2D point = getPointFromSL((int) s, (int) l, slRadius);
    double pX = centerX - point.getX();
    double pY = centerY - point.getY();
    double endPointX;
    double endPointY;
    if (Math.pow(pX - centerX, 2) + Math.pow(pY - centerY, 2) < Math.pow(slRadius - 2, 2)) {
        endPointX = pX - selector.getPrefWidth() / 2;
        endPointY = pY - selector.getPrefHeight() / 2;
    } else {
        double dx = pX - centerX;
        double dy = pY - centerY;
        theta = Math.atan2(dy, dx);
        x = centerX + (slRadius - 2) * Math.cos(theta);
        y = centerY + (slRadius - 2) * Math.sin(theta);
        endPointX = x - selector.getPrefWidth() / 2;
        endPointY = y - selector.getPrefHeight() / 2;
    }
    selectorTransition = new CachedTransition(selector, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(selector.translateXProperty(), endPointX, Interpolator.EASE_BOTH), new KeyValue(selector.translateYProperty(), endPointY, Interpolator.EASE_BOTH)))) {

        {
            setCycleDuration(Duration.millis(160));
            setDelay(Duration.seconds(0));
        }
    };
    if (pTrans != null)
        pTrans.stop();
    pTrans = new ParallelTransition(colorsTransition, selectorTransition);
    pTrans.setOnFinished((finish) -> {
        if (pTrans.getStatus().equals(Status.STOPPED))
            allowColorChange = true;
    });
    pTrans.play();
    refreshHSLCircle();
}
Also used : Point2D(javafx.geometry.Point2D) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 17 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getSLCricle.

private Image getSLCricle(int width, int height, List<Stop> stops) {
    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;
}
Also used : WritableImage(javafx.scene.image.WritableImage) Point2D(javafx.geometry.Point2D) PixelWriter(javafx.scene.image.PixelWriter)

Example 18 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getHuesCircle.

private Image getHuesCircle(int width, int height, List<Stop> stops) {
    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;
}
Also used : WritableImage(javafx.scene.image.WritableImage) Point2D(javafx.geometry.Point2D) PixelWriter(javafx.scene.image.PixelWriter)

Example 19 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXCustomColorPicker method init.

private void init(DoubleProperty rotationAngle, double initControlX1, double initControlY1) {
    Circle innerCircle = new Circle(centerX, centerY, radius, Color.TRANSPARENT);
    Circle outerCircle = new Circle(centerX, centerY, radius * 2, Color.web("blue", 0.5));
    // Create a composite shape of 4 cubic curves
    // create 2 cubic curves of the shape
    createQuadraticCurve(rotationAngle, initControlX1, initControlY1);
    // inner circle curve
    CubicCurve innerCircleCurve = new CubicCurve();
    innerCircleCurve.startXProperty().bind(curves.get(0).startXProperty());
    innerCircleCurve.startYProperty().bind(curves.get(0).startYProperty());
    innerCircleCurve.endXProperty().bind(curves.get(1).startXProperty());
    innerCircleCurve.endYProperty().bind(curves.get(1).startYProperty());
    curves.get(0).startXProperty().addListener((o, oldVal, newVal) -> {
        Point2D controlPoint = makeControlPoint(newVal.doubleValue(), curves.get(0).getStartY(), innerCircle, shapesNumber, -1);
        innerCircleCurve.setControlX1(controlPoint.getX());
        innerCircleCurve.setControlY1(controlPoint.getY());
    });
    curves.get(0).startYProperty().addListener((o, oldVal, newVal) -> {
        Point2D controlPoint = makeControlPoint(curves.get(0).getStartX(), newVal.doubleValue(), innerCircle, shapesNumber, -1);
        innerCircleCurve.setControlX1(controlPoint.getX());
        innerCircleCurve.setControlY1(controlPoint.getY());
    });
    curves.get(1).startXProperty().addListener((o, oldVal, newVal) -> {
        Point2D controlPoint = makeControlPoint(newVal.doubleValue(), curves.get(1).getStartY(), innerCircle, shapesNumber, 1);
        innerCircleCurve.setControlX2(controlPoint.getX());
        innerCircleCurve.setControlY2(controlPoint.getY());
    });
    curves.get(1).startYProperty().addListener((o, oldVal, newVal) -> {
        Point2D controlPoint = makeControlPoint(curves.get(1).getStartX(), newVal.doubleValue(), innerCircle, shapesNumber, 1);
        innerCircleCurve.setControlX2(controlPoint.getX());
        innerCircleCurve.setControlY2(controlPoint.getY());
    });
    Point2D controlPoint = makeControlPoint(curves.get(0).getStartX(), curves.get(0).getStartY(), innerCircle, shapesNumber, -1);
    innerCircleCurve.setControlX1(controlPoint.getX());
    innerCircleCurve.setControlY1(controlPoint.getY());
    controlPoint = makeControlPoint(curves.get(1).getStartX(), curves.get(1).getStartY(), innerCircle, shapesNumber, 1);
    innerCircleCurve.setControlX2(controlPoint.getX());
    innerCircleCurve.setControlY2(controlPoint.getY());
    //		innerCircleCurve.setStroke(Color.FORESTGREEN);
    //		innerCircleCurve.setStrokeWidth(1);
    //		innerCircleCurve.setStrokeLineCap(StrokeLineCap.ROUND);
    //		innerCircleCurve.setFill(Color.TRANSPARENT);
    //		innerCircleCurve.setMouseTransparent(true);
    //		pane.getChildren().add(new Group(  innerCircleCurve));
    // outter circle curve
    CubicCurve outerCircleCurve = new CubicCurve();
    outerCircleCurve.startXProperty().bind(curves.get(0).endXProperty());
    outerCircleCurve.startYProperty().bind(curves.get(0).endYProperty());
    outerCircleCurve.endXProperty().bind(curves.get(1).endXProperty());
    outerCircleCurve.endYProperty().bind(curves.get(1).endYProperty());
    controlPoint = makeControlPoint(curves.get(0).getEndX(), curves.get(0).getEndY(), outerCircle, shapesNumber, -1);
    outerCircleCurve.setControlX1(controlPoint.getX());
    outerCircleCurve.setControlY1(controlPoint.getY());
    controlPoint = makeControlPoint(curves.get(1).getEndX(), curves.get(1).getEndY(), outerCircle, shapesNumber, 1);
    outerCircleCurve.setControlX2(controlPoint.getX());
    outerCircleCurve.setControlY2(controlPoint.getY());
    //		outerCircleCurve.setStroke(Color.FORESTGREEN);
    //		outerCircleCurve.setStrokeWidth(1);
    //		outerCircleCurve.setStrokeLineCap(StrokeLineCap.ROUND);
    //		outerCircleCurve.setFill(Color.TRANSPARENT);
    //		outerCircleCurve.setMouseTransparent(true);
    //		pane.getChildren().add(new Group(outerCircleCurve));
    startPoint = new MoveTo();
    startPoint.xProperty().bind(curves.get(0).startXProperty());
    startPoint.yProperty().bind(curves.get(0).startYProperty());
    curve0To = new CubicCurveTo();
    curve0To.controlX1Property().bind(curves.get(0).controlX1Property());
    curve0To.controlY1Property().bind(curves.get(0).controlY1Property());
    curve0To.controlX2Property().bind(curves.get(0).controlX2Property());
    curve0To.controlY2Property().bind(curves.get(0).controlY2Property());
    curve0To.xProperty().bind(curves.get(0).endXProperty());
    curve0To.yProperty().bind(curves.get(0).endYProperty());
    outerCircleCurveTo = new CubicCurveTo();
    outerCircleCurveTo.controlX1Property().bind(outerCircleCurve.controlX1Property());
    outerCircleCurveTo.controlY1Property().bind(outerCircleCurve.controlY1Property());
    outerCircleCurveTo.controlX2Property().bind(outerCircleCurve.controlX2Property());
    outerCircleCurveTo.controlY2Property().bind(outerCircleCurve.controlY2Property());
    outerCircleCurveTo.xProperty().bind(outerCircleCurve.endXProperty());
    outerCircleCurveTo.yProperty().bind(outerCircleCurve.endYProperty());
    curve1To = new CubicCurveTo();
    curve1To.controlX1Property().bind(curves.get(1).controlX2Property());
    curve1To.controlY1Property().bind(curves.get(1).controlY2Property());
    curve1To.controlX2Property().bind(curves.get(1).controlX1Property());
    curve1To.controlY2Property().bind(curves.get(1).controlY1Property());
    curve1To.xProperty().bind(curves.get(1).startXProperty());
    curve1To.yProperty().bind(curves.get(1).startYProperty());
    innerCircleCurveTo = new CubicCurveTo();
    innerCircleCurveTo.controlX1Property().bind(innerCircleCurve.controlX2Property());
    innerCircleCurveTo.controlY1Property().bind(innerCircleCurve.controlY2Property());
    innerCircleCurveTo.controlX2Property().bind(innerCircleCurve.controlX1Property());
    innerCircleCurveTo.controlY2Property().bind(innerCircleCurve.controlY1Property());
    innerCircleCurveTo.xProperty().bind(innerCircleCurve.startXProperty());
    innerCircleCurveTo.yProperty().bind(innerCircleCurve.startYProperty());
}
Also used : Point2D(javafx.geometry.Point2D)

Example 20 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXCustomColorPicker method makeControlPoint.

private Point2D makeControlPoint(double endX, double endY, Circle circle, int numSegments, int direction) {
    double controlPointDistance = (4.0 / 3.0) * Math.tan(Math.PI / (2 * numSegments)) * circle.getRadius();
    Point2D center = new Point2D(circle.getCenterX(), circle.getCenterY());
    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);
    perp = end.add(diff);
    return perp;
}
Also used : Point2D(javafx.geometry.Point2D)

Aggregations

Point2D (javafx.geometry.Point2D)29 Point3D (org.fxyz.geometry.Point3D)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Collectors (java.util.stream.Collectors)7 IntStream (java.util.stream.IntStream)7 TriangleMesh (javafx.scene.shape.TriangleMesh)7 Face3 (org.fxyz.geometry.Face3)7 HashMap (java.util.HashMap)6 DoubleStream (java.util.stream.DoubleStream)6 IntegerProperty (javafx.beans.property.IntegerProperty)6 ObjectProperty (javafx.beans.property.ObjectProperty)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 DepthTest (javafx.scene.DepthTest)6 CullFace (javafx.scene.shape.CullFace)6 DrawMode (javafx.scene.shape.DrawMode)6 FloatCollector (org.fxyz.utils.FloatCollector)6 DoubleProperty (javafx.beans.property.DoubleProperty)5 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)5