Example usage for javafx.scene.effect Lighting Lighting

List of usage examples for javafx.scene.effect Lighting Lighting

Introduction

In this page you can find the example usage for javafx.scene.effect Lighting Lighting.

Prototype

public Lighting() 

Source Link

Document

Creates a new instance of Lighting with default parameters.

Usage

From source file:Main.java

public static void main(String[] args) {
    ObjectProperty<Lighting> root = new SimpleObjectProperty<Lighting>();
    final ObjectBinding<Color> colorBinding = Bindings.select(root, "light", "color");
    colorBinding.addListener(new ChangeListener<Color>() {
        @Override//from   w  w w  . j av a  2 s .c o  m
        public void changed(ObservableValue<? extends Color> observableValue, Color oldValue, Color newValue) {
            System.out.println(oldValue + "new = " + newValue);
        }
    });
    Light firstLight = new Light.Point();
    firstLight.setColor(Color.BLACK);

    Light secondLight = new Light.Point();
    secondLight.setColor(Color.WHITE);

    Lighting firstLighting = new Lighting();
    firstLighting.setLight(firstLight);

    root.set(firstLighting);
    firstLighting.setLight(firstLight);
    firstLight.setColor(Color.RED);
}

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox box = new VBox();
    final Scene scene = new Scene(box, 300, 250);
    scene.setFill(null);//from   w w  w .j ava 2s . c om

    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0);

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0);

    Text t = new Text();
    t.setText("JavaFX!");
    t.setFill(Color.RED);
    t.setFont(Font.font(null, FontWeight.BOLD, 90));
    t.setX(10.0);
    t.setY(10.0);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    box.getChildren().add(t);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(final Stage stage) throws Exception {
    Group rootGroup = new Group();
    Scene scene = new Scene(rootGroup, 800, 400);

    Text text1 = new Text(25, 25, "java2s.com");
    text1.setFill(Color.CHOCOLATE);
    text1.setFont(Font.font(java.awt.Font.MONOSPACED, 35));

    final Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0);/*from  w  w w  .  jav  a 2s .  c  o m*/
    final Lighting lighting = new Lighting();
    lighting.setLight(light);
    lighting.setSurfaceScale(9.0);
    text1.setEffect(lighting);

    rootGroup.getChildren().add(text1);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group g = new Group();
    final Scene scene = new Scene(g, 300, 250);
    scene.setFill(null);/*from   w w  w .  j  a  va 2s  . co  m*/

    Light.Spot light = new Light.Spot();
    light.setX(0);
    light.setY(100);
    light.setZ(50);
    light.setPointsAtX(400);
    light.setPointsAtY(0);
    light.setPointsAtZ(0);
    light.setSpecularExponent(2);

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0);

    Text t = new Text();
    t.setText("Spot");
    t.setFill(Color.RED);
    t.setFont(Font.font(null, FontWeight.BOLD, 90));
    t.setX(10.0);
    t.setY(10.0);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    Rectangle r = new Rectangle();
    r.setFill(Color.BLACK);

    g.getChildren().add(r);
    g.getChildren().add(t);

    r.setWidth(t.getLayoutBounds().getWidth() + 30);
    r.setHeight(t.getLayoutBounds().getHeight() + 20);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");

    final Circle circ = new Circle(40, 40, 30);
    final Group root = new Group(circ);

    final Scene scene = new Scene(root, 800, 400, Color.BEIGE);

    final Text text1 = new Text(25, 25, "java2s.com");
    text1.setFill(Color.DARKBLUE);
    text1.setFont(Font.font(java.awt.Font.SERIF, 25));
    final Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0);//  w w w  . j a v a2 s .c  o  m
    final Lighting lighting = new Lighting();
    lighting.setLight(light);
    lighting.setSurfaceScale(9.0);
    text1.setEffect(lighting);

    root.getChildren().add(text1);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

static Node distantLight() {
    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0f);/*  w  w  w . j a  va2  s .  c om*/
    light.setElevation(30.0f);

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0f);

    final Text t = new Text();
    t.setText("Distant Light");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 70));
    t.setX(10.0f);
    t.setY(50.0f);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    final Rectangle r = new Rectangle();
    r.setFill(Color.BLACK);

    Group g = new Group();
    g.getChildren().add(r);
    g.getChildren().add(t);

    g.setTranslateY(460);

    return g;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group p = new Group();
    Scene scene = new Scene(p);
    stage.setScene(scene);// w  w  w.j  a va  2  s. co m
    stage.setWidth(500);
    stage.setHeight(500);
    p.setTranslateX(80);
    p.setTranslateY(80);

    //create a circle with effect
    final Circle circle = new Circle(20, Color.rgb(156, 216, 255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text(i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    p.getChildren().add(stack);
    stage.show();

    //create a timeline for moving the circle
    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //You can add a specific action when each frame is started.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }
    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.millis(2000);
    //one can add a specific action when the keyframe is reached
    EventHandler onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            stack.setTranslateX(java.lang.Math.random() * 200 - 100);
            //reset counter
            i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished, keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    timeline.play();
    timer.start();
}

From source file:Main.java

static Node lighting() {
    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0f);//w ww .j ava  2  s.  co m

    Lighting l = new Lighting();
    l.setLight(light);
    l.setSurfaceScale(5.0f);

    Text t = new Text();
    t.setText("JavaFX\nLighting!");
    t.setFill(Color.RED);
    t.setFont(Font.font("null", FontWeight.BOLD, 70));
    t.setX(500.0f);
    t.setY(100.0f);
    t.setTextOrigin(VPos.TOP);

    t.setEffect(l);

    t.setTranslateX(0);
    t.setTranslateY(320);

    return t;
}