use of javafx.scene.paint.LinearGradient in project FXyzLib by Birdasaur.
the class SimpleRayTest method start.
@Override
public void start(Stage primaryStage) throws Exception {
// add cameraTransform so it doesn't affect all nodes
rayLight.getScope().add(cameraTransform);
camera = new PerspectiveCamera(true);
cameraTransform.setTranslate(0, 0, 0);
cameraTransform.getChildren().addAll(camera);
camera.setNearClip(0.1);
camera.setFarClip(1000000.0);
camera.setFieldOfView(42);
camera.setTranslateZ(-5000);
PointLight light = new PointLight(Color.GAINSBORO);
PointLight light2 = new PointLight(Color.YELLOW);
light2.setTranslateY(-2000);
//create a target
target1 = new Sphere(100);
target1.setTranslateX(300);
target1.setTranslateY(300);
target1.setTranslateZ(1000);
target1.setMaterial(red);
// create another target
target2 = new Sphere(100);
target2.setTranslateX(800);
target2.setTranslateY(-1200);
target2.setTranslateZ(-500);
target2.setMaterial(blue);
root.getChildren().addAll(cameraTransform, target1, target2, light, light2, rayLight);
root.setAutoSizeChildren(false);
Scene scene = new Scene((root), 1200, 800, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(0.5, Color.DEEPSKYBLUE.darker()), new Stop(1.0, Color.BLACK) };
LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);
scene.setFill(lg);
//First person shooter keyboard movement
scene.setOnKeyPressed(ke -> {
double change = 10.0;
if (ke.isShiftDown()) {
change = 50.0;
}
KeyCode keycode = ke.getCode();
if (keycode == KeyCode.W) {
camera.setTranslateZ(camera.getTranslateZ() + change);
}
if (keycode == KeyCode.S) {
camera.setTranslateZ(camera.getTranslateZ() - change);
}
if (keycode == KeyCode.A) {
camera.setTranslateX(camera.getTranslateX() - change);
}
if (keycode == KeyCode.D) {
camera.setTranslateX(camera.getTranslateX() + change);
}
if (keycode == KeyCode.CONTROL) {
fireRay = false;
}
});
scene.setOnKeyReleased(ke -> {
if (ke.getCode().equals(KeyCode.CONTROL)) {
fireRay = true;
}
});
scene.setOnMousePressed(e -> {
mousePosX = e.getSceneX();
mousePosY = e.getSceneY();
mouseOldX = e.getSceneX();
mouseOldY = e.getSceneY();
if (fireRay) {
Point3D o = e.getPickResult().getIntersectedPoint();
if (e.isPrimaryButtonDown()) {
Point3D t = Point3D.ZERO.add(target2.getTranslateX(), target2.getTranslateY(), target2.getTranslateZ()), d = t.subtract(o);
Ray r = new Ray(o, d);
double dist = t.distance(o);
if (target2.getBoundsInParent().contains(r.project(dist))) {
animateRayTo(r, target2, Duration.seconds(2));
System.out.println("Target Contains Ray!\n" + r + "\nTarget Bounds: " + target2.getBoundsInParent() + "\nDistance: " + dist + "\n");
}
e.consume();
} else if (e.isSecondaryButtonDown()) {
Point3D tgt = Point3D.ZERO.add(target1.getTranslateX(), target1.getTranslateY(), target1.getTranslateZ()), dir = tgt.subtract(o);
Ray r = new Ray(o, dir);
double dist = tgt.distance(o);
if (target1.getBoundsInParent().contains(r.project(dist))) {
animateRayTo(r, target1, Duration.seconds(2));
System.out.println("Target Contains Ray: " + target1.getBoundsInParent().contains(r.project(dist)) + "\n" + r + "\nTarget Bounds: " + target1.getBoundsInParent() + "\nDistance: " + dist + "\n");
}
e.consume();
}
}
});
scene.setOnMouseDragged(e -> {
if (!fireRay) {
mouseOldX = mousePosX;
mouseOldY = mousePosY;
mousePosX = e.getSceneX();
mousePosY = e.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
double modifier = 10.0;
double modifierFactor = 0.1;
if (e.isControlDown()) {
modifier = 0.1;
}
if (e.isShiftDown()) {
modifier = 50.0;
}
if (e.isPrimaryButtonDown()) {
cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
} else if (e.isSecondaryButtonDown()) {
double z = camera.getTranslateZ();
double newZ = z + mouseDeltaX * modifierFactor * modifier;
camera.setTranslateZ(newZ);
} else if (e.isMiddleButtonDown()) {
cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
}
}
});
primaryStage.setTitle("Hello Ray! Animated Visual of a Ray casting");
primaryStage.setScene(scene);
primaryStage.show();
}
use of javafx.scene.paint.LinearGradient in project FXyzLib by Birdasaur.
the class Patterns method createCarbonKevlarPattern.
public static final ImagePattern createCarbonKevlarPattern() {
final double WIDTH = 12;
final double HEIGHT = 12;
final Canvas CANVAS = new Canvas(WIDTH, HEIGHT);
final GraphicsContext CTX = CANVAS.getGraphicsContext2D();
double offsetY = 0;
/// 1= border=yellow=dark========================================================
CTX.beginPath();
CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5);
CTX.closePath();
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(105, 105, 0)), new Stop(1, Color.rgb(98, 98, 0))));
CTX.fill();
// 2=body=yellow==============================
CTX.beginPath();
CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666);
CTX.closePath();
offsetY = 0;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(138, 138, 0)), new Stop(1, Color.rgb(130, 130, 0))));
CTX.fill();
// 3=border=yellow=dark=============================
CTX.beginPath();
CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
CTX.closePath();
offsetY = 0.5;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(105, 105, 0)), new Stop(1, Color.rgb(98, 98, 0))));
CTX.fill();
// 4=body=yellow============================================================
CTX.beginPath();
CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666);
CTX.closePath();
offsetY = 0.5;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(138, 138, 0)), new Stop(1, Color.rgb(130, 130, 0))));
CTX.fill();
// 5= border=gray=dark============================
CTX.beginPath();
CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5);
CTX.closePath();
offsetY = 0;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(30, 30, 30))));
CTX.fill();
// 6=body=gray=============================
CTX.beginPath();
CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666);
CTX.closePath();
offsetY = 0.083333;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45))));
CTX.fill();
// 7= border=gray=dark=============================
CTX.beginPath();
CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
CTX.closePath();
offsetY = 0.5;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40))));
CTX.fill();
// 8= body=gray=light==============================
CTX.beginPath();
CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666);
CTX.closePath();
offsetY = 0.583333;
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45))));
CTX.fill();
final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false);
return PATTERN;
}
use of javafx.scene.paint.LinearGradient in project fxexperience2 by EricCanull.
the class PaintPickerController method onLinearButtonAction.
@FXML
void onLinearButtonAction(ActionEvent event) {
final ToggleButton tb = (ToggleButton) event.getTarget();
assert tb == linearToggleButton;
final Paint value = gradientPicker.getValue(Mode.LINEAR);
assert value instanceof LinearGradient;
// Update UI
setMode(value);
gradientPicker.setMode(value);
gradientPicker.updatePreview(value);
// Update model
setPaintProperty(value);
event.consume();
}
use of javafx.scene.paint.LinearGradient in project fxexperience2 by EricCanull.
the class PaintPickerController method getMode.
public Mode getMode() {
final Mode mode;
final Paint value = getPaintProperty();
if (value instanceof Color) {
mode = Mode.COLOR;
} else if (value instanceof LinearGradient) {
mode = Mode.LINEAR;
} else {
assert value instanceof RadialGradient;
mode = Mode.RADIAL;
}
return mode;
}
Aggregations